linux oracle用户手动执行.sh脚本正常,执行crontab定时任务提示 #!/bin/bash: No such file or directory。
没有找到需要执行的文件或目录,请检查要执行脚本的路径,在crontab中写绝对路径。
找不到执行文件的目录,是不是路径设置错
环境变量惹的祸,可以尝试在crontab中直接引入环境变量解决问题
执行脚本前再写一个刷新环境变量
环境变量写上,或是在计划任务前边再加一个source 一下profile
把文件的权限改一下试试
1.crontab编辑后要重启crond服务才会生效
/etc/init.d/crond restart
2.参考步骤
计划任务:每三分钟运行一次(现在的crotab文件有设置一些环境参数要注意)
cd /root
echo "cd /root">>test.sh
echo "date >>t.txt">>test.sh
chmod +x test.sh
echo "*/3 * * * * root sh /root/test.sh" >>/etc/crontab
/etc/init.d/crond restart
你在试试这个
source ~/.bash_profile
基本上都是环境变量的问题,在脚本第二行添加 source /etc/profile