Run bash script on boot time on centos

How to Auto Execute Commands/Scripts During Reboot or Startup on centos . Many method to execute a command or run scripts during startup.

Method 1: Linux Execute Cron Job After System Reboot

Use @reboot in cron scheduler. It will run once, at startup after reboot your system.

Edit crontab

# crontab -e

To run a script called /home/huuphan/auto_excute.sh

@reboot /home/huuphan/auto_excute.sh

Method 2: Using /etc/rc.d/rc.local file

This method is vaild for systemd-based distributions. To grant execute permission to /etc/rc.d/rc.local

# chmod +x /etc/rc.d/rc.local

And add your script at the bottom of the file /etc/rc.d/rc.local

# echo "/home/huuphan/auto_excute.sh" >> /etc/rc.d/rc.local

Conclusion

In this article, how to Run bash script on boot time on centos. Use two method: Crontab and /etc/rc.d/rc.local file.

Comments

Popular posts from this blog

zimbra some services are not running [Solve problem]

Bash script list all IP addresses connected to Server

How to install php7 on centos 6