CentOS - RHEL 7 - How To Create Custom Script To Run Automatically During Boot - The Geek Diary
CentOS - RHEL 7 - How To Create Custom Script To Run Automatically During Boot - The Geek Diary
boot
By admin (https://www.thegeekdiary.com/author/sandeep_patil/)
In RHEL 5 and 6, we were using automatic startup feature of RHEL through /etc/rc.d/init.d to run any script at system boot.
Starting with RHEL 7 init is replaced by systemd and the prior method is now deprecated. There is another way in RHEL 7 to
do the same.
# vi /var/tmp/test_script.sh
#!/bin/bash
echo "This is a sample script to test auto run during boot" > /var/tmp/script.out
echo "The time the script run was --> `date`" >> /var/tmp/script.out
https://www.thegeekdiary.com/centos-rhel-7-how-to-make-custom-script-to-run-automatically-during-boot/ 1/4
5/12/2019 CentOS / RHEL 7 : How to create custom script to run automatically during boot – The Geek Diary
# ls -lrt /usr/local/sbin/myscript.sh
# chmod +x /var/tmp/test_script.sh
# vi /etc/systemd/system/sample.service
[Unit]
Description=Description for sample script goes here
After=network.target
[Service]
Type=simple
ExecStart=/var/tmp/test_script.sh
TimeoutStartSec=0
[Install]
WantedBy=default.target
Here,
After= : If the script needs any other system facilities (networking, etc), modify the [Unit] section to i
Type= : Switch Type=simple for Type=idle in the [Service] section to delay execution of the script until a
WantedBy= : target to run the sample script in
https://www.thegeekdiary.com/centos-rhel-7-how-to-make-custom-script-to-run-automatically-during-boot/ 2/4
5/12/2019 CentOS / RHEL 7 : How to create custom script to run automatically during boot – The Geek Diary
# systemctl daemon-reload
4. Reboot the host to verify whether the scripts are starting as expected during system boot.
# systemctl reboot
Y O U M AY A L S O L I K E
https://www.thegeekdiary.com/centos-rhel-7-how-to-make-custom-script-to-run-automatically-during-boot/ 3/4
5/12/2019 CentOS / RHEL 7 : How to create custom script to run automatically during boot – The Geek Diary
https://www.thegeekdiary.com/centos-rhel-7-how-to-make-custom-script-to-run-automatically-during-boot/ 4/4