Bash 电子邮件不起作用的cronjob
更新: 当我在下面的脚本中回显$res时,我得到了以下结果,我想这是因为脚本本身包含单词searchd!!因此,在执行cronjob进程的瞬间,$res变为空Bash 电子邮件不起作用的cronjob,bash,shell,crontab,Bash,Shell,Crontab,更新: 当我在下面的脚本中回显$res时,我得到了以下结果,我想这是因为脚本本身包含单词searchd!!因此,在执行cronjob进程的瞬间,$res变为空 我重新命名了脚本,问题解决了 root 10769 7177 0 23:31 pts/1 00:00:00 /bin/bash /home/scripts/monitor_searchd.sh root 10770 10769 0 23:31 pts/1 00:00:00 /bin/bash /home/scripts/monitor_s
我重新命名了脚本,问题解决了 root 10769 7177 0 23:31 pts/1 00:00:00 /bin/bash /home/scripts/monitor_searchd.sh root 10770 10769 0 23:31 pts/1 00:00:00 /bin/bash /home/scripts/monitor_searchd.sh root 10769 7177 0 23:31 pts/1 00:00:00/bin/bash/home/scripts/monitor\u searchd.sh root 10770 10769 0 23:31 pts/1 00:00:00/bin/bash/home/scripts/monitor\u searchd.sh 原始问题: 我有一个shell脚本,当我在shell中调用它时,它可以工作,但是当以下面的方式放入crontab时,它不工作(不发送电子邮件)。奇怪的是,cron日志显示进程每分钟都在运行 */1 * * * * root /home/scripts/monitor_searchd.sh */1****root/home/scripts/monitor\u searchd.sh 以下是脚本: process="java" res="`ps -ef|grep $process|grep -v grep`" if [ ! -n "$res" ]; then echo "$process is down!" | mail -s "$process is down" xxx@gmail.com fi process=“java” res=“`ps-ef | grep$process | grep-v grep`” 如果[!-n“$res”];然后 echo“$进程已关闭!”| mail-s“$进程已关闭”xxx@gmail.com fi cron日志 CROND[7370]: (root) CMD (/home/scripts/monitor_searchd.sh) CROND[7370]:(root)CMD(/home/scripts/monitor\u searchd.sh) 请补充:
echo "$process is down!" >> /tmp/monitor_searcd.log
在带有邮件的行之前
?这有助于将问题定位
还有一对小评论:
请加上
#!/bin/bash
到脚本的第一行
改变
[ ! -n "$res" ]
到
@朱贝斯特:你可以把答案写下来作为问题的答案,然后接受它。这对所有人都更好:)
[ -z "$res" ]