I created a bash script scriptToCreateFilesWithSystemD.sh
to create a file inside a directory dir4systemDfiles
Both have read-write access for all and located in home directory
I added this code inside the bash file:
[rajparayane@localhost ~]$ cat scriptToCreateFilesWithSystemD.sh
#!/bin/bash
touch /home/rajparayane/dir4systemDfiles/filecreated.$(date +"%d-%m-%Y_%I:%M:%S").txt
It creates files inside the dir dir4systemDfiles
with date and time
when I tried running the bash file it worked fine
[rajparayane@localhost ~]$ ./scriptToCreateFilesWithSystemD.sh
[rajparayane@localhost ~]$ ll dir4systemDfiles/
total 0
-rw-rw-r--. 1 rajparayane rajparayane 0 Jan 2 20:42 filecreated.02-01-2023_08:42:34.txt
Then I created a fileCreatorSystemD1.service
file to run this script automatically by placing it inside /etc/systemd/system
[rajparayane@localhost system]$ sudo cat fileCreatorSystemD1.service
[Service]
ExecStart=/home/rajparayane/scriptToCreateFilesWithSystemD.sh
The fileCreatorSystemD1.service
was automatically loaded in the systemctl list-unit-files
list
Then I ran the systemctl daemon-reload
command
The status of the fileCreatorSystemD1.service
:
[rajparayane@localhost system]$ sudo systemctl status fileCreatorSystemD1
● fileCreatorSystemD1.service
Loaded: loaded (/etc/systemd/system/fileCreatorSystemD1.service; static; vendor preset>
Active: inactive (dead)
Then I ran the command sudo systemctl start fileCreatorSystemD1
It started the service but now its status shows Active: failed
[rajparayane@localhost system]$ sudo systemctl status fileCreatorSystemD1
● fileCreatorSystemD1.service
Loaded: loaded (/etc/systemd/system/fileCreatorSystemD1.service; static; vendor preset>
Active: failed (Result: exit-code) since Mon 2023-01-02 20:27:05 IST; 2s ago
Process: 4089 ExecStart=/home/rajparayane/scriptToCreateFilesWithSystemD.sh (code=exite>
Main PID: 4089 (code=exited, status=203/EXEC)
Also It didn't execute the bash file scriptToCreateFilesWithSystemD
which was mentioned in the fileCreatorSystemD1.service
sudo cat fileCreatorSystemD1.service
[Service]
ExecStart=/home/rajparayane/scriptToCreateFilesWithSystemD.sh
scriptToCreateFilesWithSystemD.sh
from home to/user/local/bin/
and ran the commandrestorecon -Rv /usr/local/bin
which responded withRelabeled /usr/local/bin/scriptToCreateFilesWithSystemD.sh from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:bin_t:s0
– Raj Parayane Jan 02 '23 at 17:41Relabeled /usr/local/bin/scriptToCreateFilesWithSystemD.sh from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:bin_t:s0
– Raj Parayane Jan 02 '23 at 18:03restorecon
"Relabeld..." message, I'd recommend checking the man page forrestorecon
as well as an introduction to SE Linux. If you're still confused, I'd recommend opening a new Question. – Jeff Schaller Jan 03 '23 at 03:07