This is a small post on how to run some commands or scripts at the time of booting

Need for running commands/scripts at boot time

Some times we require to load some kernel modules  or run a command to accomplish a task. If your command/script have to run continuously then use init start/stop scripts instead of keeping them in /etc/rc.local.

Running commands/scripts at boot time is achieved by using /etc/rc.local where rc stands for run-control.

Example 1: Load kernel modules through /etc/rc.local file

This is common in most of the Linux flavors. Edit /etc/rc.local file to enter modprob/insmod commands to execute them at the time of booting.

	#vi /etc/rc.local

Content:

	/sbin/modprob mac80211

	/sbin/insmod /lib/modules/3.19.0-15-generic/kernel/drivers/net/wireless/iwlwifi/iwlwifi.ko

Save the file and exit.

Example 2: Run a command at the time of booting. If you don't want to run puppet agent and just want to run when the system boots use below example.

	#vi /etc/rc.local

Content:

	/usr/bin/puppet agent --no-daemonize --verbose --onetime

save the file and exit.

Example 3: Run a script at booting

	#vi /etc/rc.local

Content:

	/home/surendra/startup_script.bash

Note: Always use complete path when keeping commands in /etc/rc.local so that it will not fail if PATH variable is not consulted.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.