cron任务提示‘test_cron: command not found’,是否找不到/bin/sh?如何修复?
问题解答
首先明确:不是系统找不到/bin/sh,错误提示/bin/sh: test_cron: command not found的意思是shell找不到test_cron这个可执行文件,而非/bin/sh本身存在问题。
解决方法:
- 使用
test_cron的绝对路径执行:
cron的环境变量PATH比你登录系统时的PATH精简很多,它无法识别当前目录下的文件,必须写全文件路径。比如你的test_cron放在/home/marlon/目录下,cron任务要改成:34 7 * * * /home/marlon/test_cron > /tmp/stdout.log 2> /tmp/stderr.log - 确保
test_cron有可执行权限:
运行以下命令给文件添加执行权限:chmod +x /path/to/test_cron - (可选)在cron任务中指定PATH:
如果不想写绝对路径,可以在任务里先设置包含test_cron所在目录的PATH,比如:34 7 * * * PATH=$PATH:/path/to/test_cron/directory test_cron > /tmp/stdout.log 2> /tmp/stderr.log
内容的提问来源于stack exchange,提问作者marlon
相关产品推荐
相关产品推荐

