[英]Server patching email notification linux script
I need to create an email notification linux script which can be used in the server patching activity.我需要创建一个电子邮件通知 linux 脚本,该脚本可用于服务器修补活动。 I have created one script for the same but getting some errors.我为此创建了一个脚本,但遇到了一些错误。 Can anyone please check what's the issue.任何人都可以请检查是什么问题。 Script -脚本 -
#email constants
export to_addresses=xyz@abc.com
auth_1_app_path=/export/home/apps/test1/dev1;
function sendServerPatchingSuccessMail()
{
printf "HI Team,\r\n\r\nServer patching activity has been done successfully.\r\n\r\nRequest eText DEV team to validate the server patching changes.\r\n\r\nTotal time taken = $(( ($end_date-$start_date) / ( 60) )) minutes.\r\n\r\nRegards,\r\nAdmin\r\n\r\nNote: This is an auto generated mail, please do not reply. " | mail -s "server patching activity is done sucessfully." $to_addresses -c $cc_addresses
}
function sendServerPatchingStartMail()
{
printf "Hi Team,\r\n\r\nServer patching activity has started at $start_date.\r\n\r\nRequest eText DEV team to validate the server patching changes once they receive the server patching success mail.\r\n\r\nRegards,\r\nAdmin\r\n\r\nNote: This is an auto generated mail, please do not reply. " | mail -s "server patching activity has started." $to_addresses -c $cc_addresses
}
#define list of hosts as array
servers_array=( bookvm04 #DEV1
);
function doWork() {
start_date=$(date +%Y%m%d%H%M%S);
sendServerPatchingStartMail
#stop tomcat on all hosts
echo "`date "+%Y-%m-%d %H:%M:%S"` Stop tomcat stop."
#start for each host
for i in "${servers_array[@]}"
do
export ssh_to_remote_host="ssh -l bookweb -i /export/home/apps/bookplus/.ssh/id_dsa "
case $i in
#DEV1 Book Server
b3bookvm05)
app_path=$view_1_app_path;
;;
#DEV1 Book Server
b3bookvm04)
app_path=$auth_1_app_path;
;;
*) echo "`date "+%Y-%m-%d %H:%M:%S"` $i is not a valid option exiting"
exit 0;;
esac #end case
$ssh_to_remote_host $i $app_path/scripts/stopremote
if [ "$?" -ne 0 ]
then
echo "`date "+%Y-%m-%d %H:%M:%S"` node ${i} could not be stopped"
exit 0
fi
end_date=$(date +%Y%m%d%H%M%S);
echo "`date "+%Y-%m-%d %H:%M:%S"` Total time taken = $(( ($end_date- $start_date) / ( 60) )) minutes";
sendServerPatchingSuccessMail
}
Error while executing above script执行上述脚本时出错
-bash-4.1$ sh server_patching_alert.sh
: command not foundrt.sh: line 4:
: command not foundrt.sh: line 5:
: command not foundrt.sh: line 9:
: command not foundrt.sh: line 13:
'erver_patching_alert.sh: line 14: syntax error near unexpected token `
'erver_patching_alert.sh: line 14: `function sendServerPatchingSuccessMail()
This script is working fine.这个脚本工作正常。
server_array=$(hostname)
function sendServerPatchingSuccessMail()
{
# Set email constants
to_addresses=
cc_addresses=
# Send server patching completion mail
printf "mail body - server patching activity for hostname '$server_array' has been completed successfully" | mail -s "mail subject" -c $cc_addresses $to_addresses
}
sendServerPatchingSuccessMail
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.