简体   繁体   中英

Script doesn't execute in crontab

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

refer below site for cron entries , also check your script have executable permission chmod oug+x demo.sh

https://crontab.guru/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM