简体   繁体   中英

Cronjob not working Ubuntu Server

I just finished setting up a cronjob on my server. I created my cron.sh . If I run this file via SSH with ./cron.sh everything its fine, its working as expected.

I added a new line within /etc/crontab file to run the .sh at every 5 minutes but its not working. I can't understand why.

Line added in crontab:

*/5 * * * * /var/www/sitename/wp-content/themes/themename/cron.sh >/dev/null 2>&1

Its a Ubuntu Server. I guess i use a wrong crontab file.

I already set 777 fron cron.sh.

Any ideas? Thank you

Ubuntu prefers to use

$ crontab -e

Instead of editing the file.

This will edit the crontab for the specific user you logged in as.

As I see that it is what worked to you, I post my initial comment as an answer:

Have you tried adding /bin/sh to call the script?

*/5 * * * * /bin/sh /var/www/sitename/wp-content/themes/themename/cron.sh ...

Something obscure that I just discovered this week, when manually editing /etc/crontab , you must have a newline character at the end, or apparently crond will ignore the line. This was on an older FC10 box, however some quick Googling will show this is a known issue with crontab .

如果您编辑/ etc / crontab,则需要重新启动cond service服务crond restart

First you can check already cron has scheduled or not.

crontab -l 

After this if your cron is displaying there then just restart the cron service with below command.

service crond restart

If cron is not showing there then you should run.

crontab -e

then add your cron. after that just restart the cron service.

Please make sure at once if you previously edited cron file in any editor manually then there should not be any type of character type issue else cron will not working.

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