Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. 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

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
    
what's the error message ? –  chocripple Feb 14 '13 at 5:58
    
It is not executing the script(sudo sh /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server) after killing it just terminate from execution. –  user1597811 Feb 14 '13 at 6:55
    
I got it, bcoz the script itself is matching the pattern to kill it is killing itself. –  user1597811 Feb 14 '13 at 7:03

3 Answers 3

up vote 0 down vote accepted
#!/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.3.1/bin/sym --port 8082

fi

save it as my.sh

This works fine with **symmetric-ds-3.3.1** .

Put echo "true">man.txt
share|improve this answer
1  
Fine, except don't use kill -9 as anything other than a last resort. Kill it normally, and then follow up with a -9 if it refuses to die. –  Tom O'Connor Feb 14 '13 at 8:26

If your script is killing itself then there are a couple of options

  • rename the script so that it nolonger matches you grep RE.
  • change the grep RE so that it is unique to the program you want to kill.
share|improve this answer

Change directory first

cd /var/www/symmetric-ds-3.1.6/bin/

and then run

sh sym --port 8082 --server

It probably searches for some file in current directory.

share|improve this answer
    
Thanks man. I got it, bcoz the script itself is matching the pattern to kill it is killing itself. –  user1597811 Feb 14 '13 at 7:04
    
one more question. I need to put this script in cron. I'm using sudo(i have to) in the script. Will it run without password in cron? –  user1597811 Feb 14 '13 at 7:06
    
There is NOPASSWD option for sudo (zipizap.wordpress.com/2012/03/13/…). Never tried it but it should work. –  Laurentiu Roescu Feb 14 '13 at 7:15

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.