Running Linux Commands at Startup
The following procedure enables Linux programs to start automatically after booting, without requiring users to log in first. This method is useful when automating custom daemons to act as servers with user-specific privileges.
This can also be done on the FreeBSD crontab, with some slight changes to account for the behavior of other shells.
==========
1. Edit the user crontab file.
user@host: $ crontab -e
2. Add the @reboot line with the desired command.
# BEGIN CODE
@reboot /myfolder/mydaemon.sh > /dev/null 2>&1 &
# "> /dev/null" discards standard output by redirecting to the null device.
# "2>&1" redirects standard error to standard output.
# Terminating with "&" executes the command in the background.
# END CODE
3. Save and exit crontab, then reboot the machine.
==========
==========
1. Edit the user crontab file.
user@host: $ crontab -e
2. Add the @reboot line with the desired command.
# BEGIN CODE
@reboot /myfolder/mydaemon.sh > /dev/null 2>&1 &
# "> /dev/null" discards standard output by redirecting to the null device.
# "2>&1" redirects standard error to standard output.
# Terminating with "&" executes the command in the background.
# END CODE
3. Save and exit crontab, then reboot the machine.
==========
Comments
Post a Comment