我希望通过一条消息将电子邮件结果发送到我的电子邮件中。你能告诉我该怎么做吗?下面是我的脚本的副本。所有 3 封电子邮件事项均应包含在一条消息中。我们有什么办法可以做到吗?
if ((($4) < 3000 ))
then
echo "Memory Utilization is less than 5% free of Total Memory" | mail [email protected] # first email
free -m | mail [email protected] # second email
ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=vsz|cut -c1-130|tac|head | mail -s "Please bounce high consuming jobs on server " [email protected] # third email
else
exit 0
fi
答案1
您可以使用子 shell,运行所有三个命令并一次性通过管道输出:
if ((($4) < 3000 ))
then
(
echo "Memory Utilization is less than 5% free of Total Memory"
free -m
ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=vsz|cut -c1-130|tac|head
) | mail -s "Please bounce high consuming jobs on server" [email protected]
else
exit 0
fi