-1
#!/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?

3
  • what's the error message ?
    – chocripple
    Feb 14, 2013 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. Feb 14, 2013 at 6:55
  • I got it, bcoz the script itself is matching the pattern to kill it is killing itself. Feb 14, 2013 at 7:03

3 Answers 3

0
#!/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
1
  • 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. Feb 14, 2013 at 8:26
1

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.
0

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.

3
  • Thanks man. I got it, bcoz the script itself is matching the pattern to kill it is killing itself. Feb 14, 2013 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? Feb 14, 2013 at 7:06
  • There is NOPASSWD option for sudo (zipizap.wordpress.com/2012/03/13/…). Never tried it but it should work. Feb 14, 2013 at 7:15

You must log in to answer this question.

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