今天解决两个问题,一是crontab跑脚本时总是失败,手动跑脚本又能成功,查询百度说是crontab应该是没有用上系统变量引发,所以在调用的脚本中先调用
source /etc/profile
source /root/.bash_profile
这样再跑前面的部分可以了,
另一个是在涉及到交互自动输入账号时又出问题。
我的交互输入git账号用的是expect插件,搜索百度时有人提到在crontab中使用expect不能再用interact
,而是用set timeout 60;expect eof
来替换
然后我在git获取代码的脚本中将原先的改为:
if [ ! -d /opt/kds/work/py ];then
expect -c "spawn git clone http://192.168.9.100/release/py.git; expect \"*Username*\" { send \"${CONID}\n\"; exp_continue } \"*Password*\" { send \"${CONKEY}\n\" }; set timeout 60;expect eof"
cd /opt/kds/work/py
else
cd /opt/kds/work/py
pwd
git checkout .
expect -c "spawn git pull origin; expect \"*Username*\" { send \"${CONID}\n\"; exp_continue } \"*Password*\" { send \"${CONKEY}\n\" }; set timeout 60;expect eof"
fi
然后调用一下crontab验证,搞定