Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com

This Blog is protected by DMCA.com

huuphan.com. Powered by Blogger.

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.

post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com