user3065273
user3065273

Reputation: 41

CRON not starting my python script on reboot

Problem: unable to make my python script run on reboot

I edit /etc/crontab with Nano

Edited file to read (left all default text in file)

@reboot root screen -d -m -S Rusty /root/rustynail.py

Looking through this website I see a lot of reference to PATH. As I have the full path specified I don't see this as the issue. Happy to be proved wrong.

I have tested screen by changing the CRONTAB to

@reboot root screen -d -m -S rusty ping 8.8.8.8

This works as expected

The script runs fine when i am logged in as root. Tried changing shell to shell/bin/bash.

Other things in CRONTAB work fine. I have an rsync start daily and a mount.cifs on reboot.

I have set log directories and looked in /var/log/syslog, using command grep CRON var/log/syslog

output =

(root) cmd (screen -d -m -S rusty /root/rustynail.py

Any thought will be greatly appreciated Noob to Linux, so sorry if obvious one.


Okay, so after further testing i have found this. If I use crontab -e and set the python script to run every minute

"* * * * *" screen -d -m /root/rustynail.py  >> /var/log/myscript.log 2?&1

It works as expected! I think this proves its not a PATH or BASH problem.

If I replace * * * * * with @reboot screen -d -m.. ... . .. etc It does not work.

My first thought was, the screen is being created and the script run before the network card is up, thus when the script tried to send data to an external address it fails, causing the script to stop and the screen window to close.

BUT

I have another @reboot after the script one that mounts.cifs to my NAS, that one works fine everytime. Please, any thoughts welcome.

Upvotes: 0

Views: 3117

Answers (1)

user3065273
user3065273

Reputation: 41

Fixed it by putting 30 second delay in Python script before it started doing anything Guess problem must be something to do with something not being ready before script runs. Hope this helps someone else

Thanks to anyone who spent time on this question

Upvotes: 4

Related Questions