I am using Ubuntu Server 16.04. Everytime I log in, I need to manually run my script: /home/user/ini.sh
. This script calls other scripts that need sudo
permissions, so I get the prompt, insert my password and done. Now I want to configure a way to run the script automatically when the system starts.
I have used crontab -e
and added the line
@reboot /home/user/ini.sh
This does not seem to work. I have tried different options as suggested by other users in here, here, here or here.
@reboot user /home/user/ini.sh
@reboot root /home/user/ini.sh
@reboot sh /home/user/ini.sh
*/1 * * * * /home/user/ini.sh
....
adding SHELL=/bin/bash
...
But I cannot get it to work. I have also tried
@reboot echo "yes" > /home/user/yes.txt
And the file is created - empty though, with no content inside (this demonstrates something is working but I am making a mistake somewhere).
Where is my error?
EDIT
I have also unsuccessfully tried to sudo crontab -e
and use
@reboot root /home/user/ini.sh
crontab -e
(whether your user or the root user i.e.sudo crontab -e
) should NOT include the user field after the time spec - that's only for system jobs (i.e./etc/crontab
) – steeldriver Feb 14 '18 at 13:34