0

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

7

0

Browse other questions tagged .