-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 need to run above script in cron. Will it execute in cron without password?

Any suggestions?

user1597811
  • 101
  • 2
  • We really do prefer that people try and do things for themselves rather than just dump code on us and say make it work. You should try to do it yourself and more importantly try and figure it our yourself - it's much more productive for everyone in the long run. – user9517 Feb 14 '13 at 09:12
  • _Will it execute in cron without password?_ Try it. What happens when you run the script? Does it prompt for a password? Show us the output. Show us relevant entries in the logfiles. – Stefan Lasiewski Feb 14 '13 at 18:48
  • [Better answer for the same question](http://superuser.com/a/551967/235231) and [another duplicate](http://stackoverflow.com/questions/14869523/running-script-containing-sudo-in-cron) – Sithsu Jan 20 '14 at 21:38

1 Answers1

1

If your script is run without prompted a password is entirely up to your /etc/sudoers file and which user this cron-script is run as.

If the cron-script is run as myuser, you can have the following entry in /etc/sudoers

myuser ALL=NOPASSWD: /var/www/symmetric-ds-3.1.6/bin/sym

I am not sure how sudo works when running the script with sh first, so you might want to make /var/www/symmetric-ds-3.1.6/bin/sym executable and replace this:

sudo sh /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server;

with this

sudo /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server;
pkhamre
  • 6,120
  • 3
  • 17
  • 27