• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

Startup Script

April 6, 2021

Here’s how to run a script on bootup on Rhel 7 that’s running systemd.

First create a script. It this case, it will create a file called test.txt.

#!/bin/bash
> /root/test.txt

#!/bin/bash > /root/test.txt

Make the script executable.

chmod /root/test.sh

chmod /root/test.sh

Now create a service in /etc/systemd/system/test.service

# vi /etc/systemd/system/test.service
[Unit]
Description=A test service
After=network.target
[Service]
Type=simple
ExecStart=/root/test.sh
TimeoutStartSec=0
[Install]
WantedBy=default.target

# vi /etc/systemd/system/test.service [Unit] Description=A test service After=network.target [Service] Type=simple ExecStart=/root/test.sh TimeoutStartSec=0 [Install] WantedBy=default.target

Reload systemd.

systemctl daemon-reload

systemctl daemon-reload

Enable the service.

systemctl enable test.service

systemctl enable test.service

Start the service.

systemctl start test.service

systemctl start test.service

Reboot and test.

reboot

reboot

Validate if the script ran. Check if the file was created.

Filed Under: Cloud, Linux Tagged With: bootup, rhel 7, script, systemd

Search This Website

Subscribe Via Email

  • Home
  • About
  • Archives

Copyright © 2023