linux - 服务器修补电子邮件通知 Linux 脚本

标签 linux bash shell

我需要创建一个电子邮件通知 Linux 脚本,该脚本可用于服务器修补事件。我已经为此创建了一个脚本,但出现了一些错误。任何人都可以检查一下出了什么问题。 脚本-

#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
}

执行上述脚本时出错

-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()

最佳答案

这个脚本运行良好。

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

关于linux - 服务器修补电子邮件通知 Linux 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36029325/

相关文章:

linux - 快速密码套件

linux - 获取 Red Hat Linux 的 CD-R 的 SCSI id

linux - BASH 脚本和 AWK 之间的区别

regex - 需要帮助使用 grep 从列表中提取名称

linux - 我的 sh 代码不起作用,需要帮助

linux - TurtleSim 在 Windows 10 上显示 Linux

c++ - OpenCV 3.1.0 无法使用 CMake 进行编译

ruby - 为什么 bash -l -c "CMD"让 ruby 找到我的 gem ?

Bash 补全 - 如何摆脱不需要的 Tab 键?

bash - 在bash脚本中将值传递给标志