Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
#!/bin/bash
value=$(<man.txt)
echo "$value"

if [ "$value" == "true" ]; then
    echo "startedif_manthan"
      ps -ef|grep sym |awk '{ print $2 }'|sudo  xargs kill -9;
      sleep 30;
    sudo sh /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server;
fi

Hi There, I have this script killing a process and restart the script in some time. It is killing the script normally but the restart script (sudo sh /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server) is not running properly. when I run the script manually also it is giving problems. I don't know whether it is a shell script or not. But when I tried to go manually to the script location and execute this command ./sym --port 8082 --server the script running normally.

Any suggestions?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Based on what I see, the process list matching command is going to kill the grep which is doing the pattern match and prevent further execution. A quick hack would be to remove grep itself from the search results:

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

A better method would be to read up on pgrep/pkill and use those. :)

share|improve this answer
    
I got it, bcoz the script itself is matching the pattern to kill it is killing itself –  user1597811 Feb 14 '13 at 7:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.