Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
#!/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
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

You must log in to answer this question.

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