I'm writing a linux service test-thingy as a precursor to a project I am developing. I am trying to understand how it works, and why its failing right now.
My current goal is to create a linux (Ubuntu specifically in my case) service that monitors a text file,
check.txt, for changes. The current contents of this file is simply the word "yes" on the first line (no quotes though). I want my service to change the word "yes" to "no", and change it back to "no" if I go in and change it to "yes" at any point in time. This is what I have so far.
My service file: trial.service
[Service] ExecStart=/home/jeremiahdgage/trial.sh User=root Group=root
I know using root here isn't the best practice, but it will be necessary later on, so I am leaving it for now.
My bash file: trial.sh
#!/bin/bash while true do line=$(head -n 1 filename) if [ "$line" == "yes" ] then sudo sed -i 's/yes/no/g' /home/jeremiahdgage/check.txt fi echo changes made at $(date) sleep 1 done
while true means that it goes forever,
line is the first line of my document. I check the first line to see if its "yes" then I use
sed to swap it for "no". I close my if, echo the time and sleep for 1 ms before repeating the process again.
However, something is wrong because my service fails to start... If I check my status with
systemctl status trial.service, it says there is a "permission denied" error at Exec.
What did I do wrong?
Service now starts but bash code does not work.