0

Occasionally (it's pretty rare) my VPS provider has to reboot my VPS in order to fix issues or apply a patch. Is there any way to run commands as my user automatically once the VPS reboots? I've read about putting scripts in /etc/rc.local but my understanding is that those scripts will be run as root. In particular I would like to run the following commands:

screen -U -S Irssi irssi
screen -S rtorrent rtorrent

This way Irssi will automatically reconnect to its IRC servers and rtorrent will begin seeding again so that they don't have to wait for me to see the email from my VPS provider, login, and restart them manually. Any advice would be much appreciated!

1 Answer 1

0

See /etc/crontab

You can set it up to start something with a "user" and have options

string         meaning
------         -------
@reboot        Run once, at startup.
@yearly        Run once a year, "0 0 1 1 *".
@annually      (same as @yearly)
@monthly       Run once a month, "0 0 1 * *".
@weekly        Run once a week, "0 0 * * 0".
@daily         Run once a day, "0 0 * * *".
@midnight      (same as @daily)
@hourly        Run once an hour, "0 * * * *".

Default on any Ubuntu machine:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

So basically you want somerthing like:

@reboot {your_user} {your_script}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.