作为cron作业运行而无法获得输出

时间:2018-11-02 17:20:59

标签: linux cron centos7 datastax cassandra-3.0

当我执行以下脚本时,它可以正常运行,并且通过电子邮件获得结果。但是当我将其作为cron作业运行时,它会发送0个代理。

我有一个低于纸条t(countagentid.sh)..

if [ -e /home/countagentid.csv ]
then
    rm -rf /home/countagentid.csv
fi

cqlsh -f countagentid.cql `hostname -I`  -u cassandra -p password -- (countagentid.cql has cql statment which will generate the output of cql query and save in csv format)
OUTPUT="$(cat /home/countagentid.csv |sort|uniq|wc -l)" --I sort & get the distinct values of the csv and assign it to $OUTPUT variable 
clustername=`cat /etc/cassandra/conf/cassandra.yaml |grep cluster_name |cut -f2 -d :`
mailalert(){
/sbin/sendmail -F Cassandra -it <<END_MESSAGE
To: test@gmail.com
Subject: Number of  agents in Cassandra $clustername

$OUTPUT  Number of  agents.
END_MESSAGE
}
mailalert

1 个答案:

答案 0 :(得分:0)

将脚本放在其他路径上。

运行以下命令并共享输出日志。

sh -x script_name.sh

Gautam Sheladiya