How to automatically execute shell script at startup boot on systemd Linux - LinuxConfig.org


#1

The following example below will serve as a basic template to be later modified to suit your specific needs. In the example below we will check a disk space of a /home/ directory during a boot time and write a report to /root/ directory.


This is a companion discussion topic for the original entry at https://linuxconfig.org/how-to-automatically-execute-shell-script-at-startup-boot-on-systemd-linux

#2

BrunoBronosky -> Guest

Linux works by having specific text in files in specific locations. There is no clicky graphic interface. The file system is the Registry™. Lot’s of projects have built GUI interfaces to run on Linux. But Linux is not GUI.


#3

Corey Drew Bruce -> Guest

Yes there is, in Xubuntu for example you just go to session and startup to see your startup applications or add your own to enable or disable. Different desktop environments will have there own applications for this.


#4

Gaurav Mittal

Hi,

I have exactly did the above steps. and when I execute the start of the service I see in status that the script gets executed. But when I check the process, nothing is there. The only difference is i am executing the script as a different user.

[dmsadmin@DMS-Admin system]$ cat DMSStartup.service
[Unit]
Description = Starting the DMS Weblogic Server

[Service]
User=dmsadmin
Group=dmsgroup
ExecStart = /opt/dms/domains/DMSDomain/bin/dmsAutoSrv.sh

[Install]
WantedBy = multi-user.target
[dmsadmin@DMS-Admin system]$

#5

Mayur

Sir, am just a beginner in linux , can you please provide how to make systemctl service to start and also stop during reboot.
I have script in example/test which start and stop , /example/test/script start or stop , I want to execute this during reboot, please can u give all the details so just copy it from here, am stuck


#6

Jorge

Thank you very much for this post, really usefull!


#7

Jameson Pugh

Should probably include Type=OneShot


#8

Gerard -> Jameson Pugh

I think oneshot has to be lower case (at least on Ubuntu 16)


#9

Edward Crosby

For some reason I was not able to enable the service. I was testing within Fedora 24. I receive the following error:

# systemctl enable disk-space-check.service
Failed to enable unit: No such file or directory

UPDATE:
Never mind on this. I was able to complete the steps as root. It may be best in your article to mention that at the beginning.


#10

reader

Please delete my previous comment and use this but without this line as I made an error.
After doing some research, I figured out what the problem was. I was
missing the “Type” parameter in the [Service] section. I now created two
services and I successfully enabled them. I no longer get the
error.


#11

reader

I followed your instructions but upon running “systemctl enable disk-space-check.service” I got “Failed to execute operation: Unit file is masked” - this is in XUbuntu 16.04 Xenial. Any ideas?