2

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

2
  • The original problem is in the title: "path is not absolute". grawity's answer is the solution. Your edit introduces a totally different problem. These should be two separate questions. Commented Oct 18, 2019 at 11:59
  • Your edit in fact admits qrawity's answer was right. I did a rollback to the original version of the question. Please take our short tour and from now on stick to the "one issue -- one question" rule. Do not change the scope of a question after it gets an answer (a good answer in particular). Commented Oct 18, 2019 at 12:23

1 Answer 1

-1

In the .service file, I needed to add /bin/bash before the path to the script.

For example, for backup.service:

ExecStart=/bin/bash /root/log_watcher.sh
1
  • 1
    I'm downvoting this because it doesn't solve the original problem. The later issue should be a separate question (and then this answer would be a valid answer to it). Additionally your solution diverts attention from the script itself where the real problem is. It probably works but smells too much like voodoo. Most likely the shebang is wrong. By explicitly invoking /bin/bash you make the shebang not matter. Commented Oct 18, 2019 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .