Bash变量在执行时

时间:2014-01-08 13:40:57

标签: bash cron crontab .bash-profile

有一个bash脚本来设置一个cron作业。

start.sh:

read -e -p "Enter the path to the log directory: " -i "/home/arya/apps/" LOGPATH
read -e -p "Enter comma separated recepient email-ids:" EMAIL

CURRENT=`pwd` 
COMMAND="python ${CURRENT}/start.sh 2014-08-01T21:12:12 2014-08-01T23:12:12 $LOGPATH  $EMAIL" 
echo $COMMAND   #Here expected output is coming :  */3+1 * * * *  python /home/arya/start.sh 2014-08-01T21:12:12 2014-08-01T23:12:12 /home/arya/apps/utils anilarya280@gmail.com 
cat <(fgrep -i -v "$COMMAND" <(crontab -l)) <(echo "*/3+1 * * * *") | crontab -

这不是在crontab文件中获取$ CURRENT值。使用crontab -e命令输出查看文件:

*/3+1 * * * *         rest things are missing.

预期产出:

  */3+1 * * * *  python /home/arya/start.sh 2014-08-01T21:12:12 2014-08-01T23:12:12 /home/arya/apps/utils anilarya280@gmail.com 

这里有什么问题?

平台:UBUNTU 13.04

1 个答案:

答案 0 :(得分:1)

您需要在echo中添加COMMAND变量以显示它。

cat <(fgrep -i -v "$COMMAND" <(crontab -l)) <(echo "*/3+1 * * * * $COMMAND") | crontab -