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.

<pre lang="bash">
#!/bin/bash
> /root/test.txt

Make the script executable.

<pre lang="bash">
chmod /root/test.sh

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

<pre lang="bash">
# 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.

<pre lang="bash">
systemctl daemon-reload

Enable the service.

<pre lang="bash">
systemctl enable test.service

Start the service.

<pre lang="bash">
systemctl start test.service

Reboot and test.

<pre lang="bash">
reboot

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