How to execute additional commands during system startup using cron

Use cron service to execute additional commands as specified user using cron during system startup.

Use @reboot time specification to execute command once after reboot.

Root can use cron service to set noop IO scheduler for sda device at boot.

$ (sudo crontab -u root -l 2>/dev/null; echo -e "# io scheduler\[email protected] (/bin/echo noop | /usr/bin/tee /sys/block/sda/queue/scheduler)") | sudo crontab -u root -
$ sudo crontab -l
# use noop io scheduler for sda
@reboot (/bin/echo noop | /usr/bin/tee /sys/block/sda/queue/scheduler)

User can use cron service to clear history at boot.

$ (crontab -u $(whoami) -l 2>/dev/null; echo -e "# clean history on reboot\[email protected] (: | /usr/bin/tee ~/.bash_history)") | crontab -u $(whoami) -
$ crontab -l
# clean history on reboot
@reboot (: | /usr/bin/tee ~/.bash_history)

There are many more possibilities as you are not limited to these two simple usage scenarios.

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.