Chinaunix

标题: sh单独执行成功,crontab失败,求助 [打印本页]

作者: Soliter    时间: 2014-10-15 23:42
标题: sh单独执行成功,crontab失败,求助
本帖最后由 Soliter 于 2014-10-15 23:46 编辑

radir="/usr/local/ra"
cd $radir
ra=`cat $radir/1.tmp`
grep $ra -rl /opt/test #确认变量传递成功
sed -i "s/${ra}/1_Org/g" /opt/test/*
grep 1_Org -rl /opt/test #确认sed执行成功
echo $RANDOM | md5sum | head -c 10 > $radir/1.tmp
ra=`cat $radir/1.tmp`
sed -i "s/1_Org/${ra}/g" /opt/test/*/*
grep $ra -rl /opt/test #确认sed执行成功

单独执行./1.sh是成功的,但是放到crontab里面会报错

Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>

grep: ::::::::::::::: No such file or directory
grep: 99c01e3230: No such file or directory
sed: -e expression #1, char 16: unterminated `s' command
sed: -e expression #1, char 27: unterminated `s' command
grep: ::::::::::::::: No such file or directory
grep: e6e97f8507: No such file or directory

个人感觉是变量的问题,但不知问题到底出在哪,求助各位,谢谢
作者: Soliter    时间: 2014-10-16 10:37
看了之前很多朋友提到环境变量的问题,决定试试
作者: Soliter    时间: 2014-10-17 10:00
使用more会生成::::::::::::::路径:::::::::::::的格式
使用cat则不会
作者: pilishenjian    时间: 2014-10-21 11:17
执行一下环境变量文件,比如 . /root/.bash_profile,或者把所有的命令写成绝对路径的方式
作者: hjfeng1988    时间: 2014-10-21 11:53
回复 1# Soliter


    贴出crontab任务,可能是任务中的用户或者时间导致,修改下时间测试。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2