脚本不在crontab中执行
我想每分钟使用crontab运行一个脚本。该脚本位于/users/robin47/desktop/script/demo.sh
上。附带说明,我将demo.sh
文件的执行许可使用chmod +x demo.sh
命令。
但这不会执行脚本。这是我关注的过程:
从终端运行crontab -e
。
robin47@mac-pro ~ % crontab -e
这在NANO中打开一个位于TMP文件夹下的NANO中的文件(crontab.xxxxxx),作为示例file:/tmp/crontab.v4dcxeju8g
。
这是我的crontab.xxxxxxx
文件:
SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin
* * * * * /bin/bash /Users/robin47/Desktop/script/demo.sh
从这里获取,这不会执行我的demo.sh
脚本。
如果我从终端运行sh命令,例如sh demo.sh
,则可以使用。而且,如果我直接回声(或在此类似的crontab中运行任何命令,例如touch,mkdir),
SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin
* * * * * echo 'hello' >> /Users/robin47/Desktop/script/text.txt
它也有效。但是不使用crontab运行脚本。感谢您的帮助,谢谢。
这是我的demo.sh
文件:
#!/bin/sh
echo "hello world" >> /Users/robin47/Desktop/script/text.txt
I wanna run a script using crontab in every minute. The script is located at /Users/robin47/Desktop/script/demo.sh
. As a side note, I give the execute permission of demo.sh
file with chmod +x demo.sh
command.
But it doesn't execute the script. Here is the process I'm following:
Run crontab -e
from the terminal.
robin47@mac-pro ~ % crontab -e
this open a file(crontab.xxxxxxx) in nano which is located under tmp folder, as an example File: /tmp/crontab.V4DcXEJU8g
.
This is my crontab.xxxxxxx
file:
SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin
* * * * * /bin/bash /Users/robin47/Desktop/script/demo.sh
Get from here, this doesn't execute my demo.sh
script.
If I run sh command from terminal like sh demo.sh
, it works. And if I directly echo(or run any command like touch, mkdir) in crontab like this
SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin
* * * * * echo 'hello' >> /Users/robin47/Desktop/script/text.txt
It also works. But doesn't run the script using crontab. I appreciate your help, Thanks.
This is my demo.sh
file:
#!/bin/sh
echo "hello world" >> /Users/robin47/Desktop/script/text.txt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅下面的网站以获取Cron条目,还请检查您的脚本已有可执行的许可
chmod oug+x demo.sh
https://crontab.guru/
refer below site for cron entries , also check your script have executable permission
chmod oug+x demo.sh
https://crontab.guru/