Just a guide on how to create a bash script to avoid more research on the net. Since I'm trying to create a script on one of my client-server which is using Fedora 30. To start with
1. Create a bash script file with .sh extension on /usr/bin
vi script.sh
2. Write the script on my example this will run a command each time you restart the server:
#! /bin/bash
cd /location{folder}
{command}
Note: remove the {} on the script and put the desire folder and command to execute on the terminal. To test your script via terminal if it working correctly. You can use the following command on terminal:
bash sciptFilename.sh
3. Set executable permission of the script by using typing :
chmod +x scriptname.sh
Once done, time to create a services on your script.
4. Create a new services on /etc/systemd/system
5. Once inside the system folder, create a file by typing on the terminal
vim script.service
[Unit]
Description = Description of the script
[Service]
Type=System
ExecStart=/bin/bash /bin/bash/Script.sh
[Install]
WantedBy=multi-user.target
6. chmod the service by using this command :
chmod 644 /etc/systemd/system/script.service
7. add the services on the startup:
systemctl enable script.service
8. You can check the status of your script by using this command:
systemctl status script.service
9. Now restart your computer and test it. Hope this help.
Comments