2

I've written the following script, intended to start a daemon and display a Zenity window, then stop the daemon when the window is closed:

#!/usr/bin/fish

if not ps aux | grep [s]erviio > /dev/null
    set -x JAVA "/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java"

    ~/Programs/serviio/bin/serviio.sh &

    zenity --info --text="Serviio is running.\nClick OK to stop." --title="Serviio"

    ~/Programs/serviio/bin/serviio.sh -stop
end

If I run the script from a terminal it works just fine. It also works from a bash terminal, which seems to show that the shebang is working as expected.

However if I create a launcher to point to the script and try to run it, nothing happens. Serviio doesn't start (I can confirm that from ps aux) and no Zenity window shows.

I've tried to figure out what it is about the script that's causing a problem but haven't had any success.

  • If I remove the test for whether Serviio is running, the script works.
  • If I keep the check but make the script display the contents of $JAVA in a Zenity window instead of launching Serviio, it works.

In other words I can't identify any single element in the script that would prevent it from running.

What could be the problem?

2
  • When you launch it from a launcher, does ~ resolve properly? Is it launching as your user? Apr 9, 2016 at 15:26
  • @glennjackman: Yes, I just tried to make it output the results of whoami and ls ~/Desktop and both were correct.
    – George T
    Apr 10, 2016 at 9:23

1 Answer 1

1

I found out why by redirecting the output of the ps command to a file. If I run the script from a launcher, grep finds the script itself (which has "serviio" in its name) and so it doesn't execute the code inside "if".

I fixed it by making what grep looks for more specific.

The main cause seems to be that if the script is run directly from a terminal it doesn't appear as a process but if it's run from a launcher then the interpreter (fish in this case) appears with the script as a parameter.

You must log in to answer this question.

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