user590849
user590849

Reputation: 11765

running linux executables from linux shell scripts

I want to run a executable from my shell script. The executable is located at /usr/bin/to_run.

My shell script(which is calling the above executable) is in the /usr/bin folder.

The shell script is :

#!/bin/bash

#kill all existing instances of synergy

killall synergys
sh "/usr/bin/synergys"

if [ $? -eq 1 ]; then
echo "synergy server started"
else
echo "error in starting"
fi

I am getting an error saying : "synergys : no process found".

When I run the same thing - /usr/bin/synergys directly from the terminal it runs fine, but from within a script there are problems. I don't understand why.

Thank you in advance.

Upvotes: 0

Views: 174

Answers (2)

Jonathan Leffler
Jonathan Leffler

Reputation: 754090

If /usr/bin/synergys is an executable and not a shell script, you will run it directly, not via the shell:

/usr/bin/synergys

Or, since /usr/bin is on the $PATH of most people, you could simply write:

synergys

If /usr/bin/synergys is actually a shell script, it should be executable (for example, 555 or -r-xr-xr-x permissions), and you can still write just synergys to execute it. You only need to use an explicit sh if the file /usr/bin/synergys is not executable and is a shell script.

Upvotes: 0

paxdiablo
paxdiablo

Reputation: 881633

That error is from the killall command, it's saying there are no candidate processes matching your argument.

If you don't want to be notified where no processes match, just use the quiet option:

killall -q synergys

From the killall man page:

-q, --quiet
     Do not complain if no processes were killed.

Upvotes: 3

Related Questions