脚本不在crontab中执行

发布于 2025-01-30 09:26:09 字数 1214 浏览 2 评论 0原文

我想每分钟使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北恋 2025-02-06 09:26:09

请参阅下面的网站以获取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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文