-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?

Tom O'Connor
  • 27,480
  • 10
  • 73
  • 148
user1597811
  • 101
  • 2

3 Answers3

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.
user9517
  • 115,471
  • 20
  • 215
  • 297
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.

Laurentiu Roescu
  • 2,266
  • 17
  • 17
  • Thanks man. I got it, bcoz the script itself is matching the pattern to kill it is killing itself. – user1597811 Feb 14 '13 at 07: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 07:06
  • There is NOPASSWD option for sudo (http://zipizap.wordpress.com/2012/03/13/allow-user-to-use-sudo-without-password/). Never tried it but it should work. – Laurentiu Roescu Feb 14 '13 at 07:15
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
user9517
  • 115,471
  • 20
  • 215
  • 297
Vivek
  • 286
  • 1
  • 3
  • 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 08:26