Crontab not running bash script on reboot
Hello.
I am trying to run a bash script whenever the computer reboots. I understand that @reboot <path_to_script> in the crontab will do this. I put "@reboot /home/bin/wormy2" at the bottom line of my crontab. /home/bin/wormy2 is my bash script. I know the bash script works and that it has executable permissions. The errors I found in /var/log/syslog are ------------------- Nov 2 17:30:30 mint cron[1421]: (CRON) INFO (pidfile fd = 3) Nov 2 17:30:30 mint cron[1421]: (CRON) INFO (Running @reboot jobs) Nov 2 17:30:30 mint CRON[1469]: (root) CMD (/home/bin/wormy2) Nov 2 17:30:30 mint CRON[1464]: (CRON) info (No MTA installed, discarding output) ------------------- I don't know what this means. Can someone help me know what I need to do to get my crontab working? Thank you! |
Is the cronjob supposed the send an email?
I asked because Quote:
|
Quote:
This is the bash script that it is trying to run: ------------------------ #!/bin/bash date >> ~/Documents/.worm_logs/worm_logs.log echo '==================================' >> ~/Documents/.worm_logs/worm_logs.log echo 'Wormy Game 2' >> ~/Documents/.worm_logs/worm_logs.log echo '==================================' >> ~/Documents/.worm_logs/worm_logs.log python3 ~/Desktop/wormy2.py >> ~/Documents/.worm_logs/worm_logs.log 2>> ~/Documents/.worm_logs/worm_logs.log nums='1 2 3 4' for i in $nums do echo ' ' >> ~/Documents/.worm_logs/worm_logs.log done ------------------------ The ~/Desktop/wormy2.py is a python program of the simple snake game. |
Quote:
PS please use code tags when posting code. See the link in my sig. PPS The “no MTA” message is probably from cron. By default it’s usually configured to send an email on error. |
I think the MTA warning is unimportant.
How do you determine that "It does not work"? There are a few potential snags in your script but nothing that should make it fail completely. Of course, root's $HOME is not the same as your user's $HOME... so the log files will show up elsewhere... Are you sure you want to run that game as root? |
A users cron job runs as that user. A system cron runs as the specified user which is typically root.
Does the script write to the log files? A cron job is not associated with a terminal window or the desktop which means the game will not eaisly run from cron. I assume the game is a window program? Is autostarting the game when you login an option? |
Quote:
|
Quote:
The simple solution is to use full path everywhere (including python and date), do not use ~ at all). Furthermore you can modify the cronjob entry like this: Code:
@reboot /home/bin/wormy2 >/tmp/wormy2.log 2>&1 |
A game? Without special tricks you cannot run a game from a crontab because it cannot connect to your "screen" (graphical display or tty/terminal).
|
Quote:
|
I'm sorry for the misunderstanding.
I wanted to try to run a simple bash script on reboot as a test, and since I already had wormy2 specified as a bash script and since I could run it from the terminal by typing 'Wormy2', I supposed that it would work in the crontab. Running this game was not my end goal. I wanted to run other bash scripts on reboot, and just wanted to test it with something. I will try to program another bash script and see if it works. PS. The game is a window game. PPS. I will avoid '~' PPPS. What I intend to do has to be run from the root crontab. |
As a simple test try
Code:
#!/bin/bash |
It worked! Thank you everyone!
Now that I know how to run bash scripts on reboot I can get on with my project. |
Quote:
|
All times are GMT -5. The time now is 11:51 PM. |