I am using Linux. I have access to the root for my user.
root@marais:~# pwd
/root
In this directory I have the following:
root@marais:~# ls
example.log log_watcher.service log_watcher.sh
log_watcher.service
[Install]
WantedBy=multi-user.target
[Unit]
Description=Log Watcher Service
[Service]
ExecStart=log_watcher.sh
log_watcher.sh
# File to output to
ErrorLogFile="./error.log"
# File to read from
ExampleLogFile="./example.log"
if [ ! -e "$ErrorLogFile" ]; then # check if file exists
echo "Creating error file $ErrorLogFile"
touch $ErrorLogFile
fi
echo "copying error messages from $ExampleLogFile to $ErrorLogFile"
# copy from one file to the other
### Challenge 1 ###
# grep ERROR $ExampleLogFile > $ErrorLogFile
### Challenge 2 ###
# tail -f $ExampleLogFile | grep --line-buffered ERROR | tee $ErrorLogFile
while :; do grep ERROR $ExampleLogFile > $ErrorLogFile; sleep 2; done
echo "done"
I run the following:
systemctl enable log_watcher
This seemed to work successfully, because I had messaged of it setting up symlinks.
Now when I try start the service:
systemctl start log_watcher
Nothing seems to happen, i.e. the log_watcher.sh
is not called.
So when I get the status:
systemctl status log_watcher
It says that the log_watcher.sh
is not called with an absolute path.
root@marais:~# systemctl status log_watcher
● log_watcher.service - Log Watcher Service
Loaded: error (Reason: Invalid argument)
Active: failed (Result: exit-code) since Fri 2019-10-18 10:49:32 CEST; 9min ago
Main PID: 2850 (code=exited, status=203/EXEC)
Oct 18 10:49:32 marais systemd[1]: Started Log Watcher Service.
Oct 18 10:49:32 marais systemd[1]: log_watcher.service: Main process exited, code=exited, status=203/EXEC
Oct 18 10:49:32 marais systemd[1]: log_watcher.service: Unit entered failed state.
Oct 18 10:49:32 marais systemd[1]: log_watcher.service: Failed with result 'exit-code'.
Oct 18 10:50:12 marais systemd[1]: [/root/log_watcher.service:8] Executable path is not absolute, ignoring: log_watcher.sh
Oct 18 10:50:12 marais systemd[1]: log_watcher.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Warning: log_watcher.service changed on disk. Run 'systemctl daemon-reload' to reload units.
When I run:
root@marais:~# readlink -f log_watcher.sh
/root/log_watcher.sh
It shows that my absolute path is /root/
, and this is the path I have defined in log_watcher.service
:
ExecStart=/root/log_watcher.sh
Question
Please can you advise how I can get this service to start and execute the log_watcher.sh
.
Thank you