Take the 2-minute tour ×

if [ "$value" == "true" ]; then

     ps -ef|grep sym |grep -v grep |awk '{ print $2 }'|sudo  xargs kill -9;

(cd /var/www/symmetric-ds-3.1.6/bin;sudo ./sym --port 8082 --server);


The second command inside brackets is not executing any idea why this is happening?

share|improve this question
What is the name of the script? –  choroba Feb 18 '13 at 11:46
restart.sh is the name of the script. –  user1597811 Feb 18 '13 at 11:54
Are you getting any error messages? How do you execute the script? –  Dennis Feb 18 '13 at 12:20
Then why do you use sudo? –  Dennis Feb 18 '13 at 14:48
Why? Without additional parameters, sudo is used to execute a command as the root user. Inside a script executed from root's crontab, sudo can't have that effect. –  Dennis Feb 25 '13 at 12:48

1 Answer 1

You must use an absolute path with sudo, for security reasons:

( sudo /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server );

Check the output of sudo -l to confirm. From the sudoers man page (1.7.x):

A Cmnd_List is a list of one or more commandnames, directories, and other aliases. A commandname is a fully qualified filename which may include shell-style wildcards (see the Wildcards section below).

sudo xargs works because xargs is (almost certainly) found in a trusted path (/usr/bin).

Also, check out pgrep and pkill, it will save you the needless ps pipe acrobatics.

You have the potential for resource leaks and other unwanted behaviour with an unconditional kill -9, see http://unix.stackexchange.com/questions/8916/why-not-kill-9-a-process .

Update you've added that you run this via root's crontab -- root has no need to use sudo, and in some cases root may be prevented from running sudo, check what sudo -l says when you are root. If you want to to be able to start a program (that doesn't switch its own uid) as a specific userid then the common way is su - username -c "command" .

share|improve this answer
Im trying these things. I will let you know after my cron got executed. –  user1597811 Feb 18 '13 at 12:19
No it is not preventing the root from running sudo bcoz the first command also got sudo in it and it is working absolutely fine. Any more suggestions? –  user1597811 Feb 25 '13 at 6:32

Your Answer


