Server Fault is a question and answer site for system and network administrators. 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

This question already has an answer here:

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;

I need to run above script in cron. Will it execute in cron without password?

Any suggestions?

share|improve this question

marked as duplicate by Michael Hampton, Khaled, Tom O'Connor, Stefan Lasiewski, TheCleaner Feb 14 '13 at 19:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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. – Iain Feb 14 '13 at 9: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

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;
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.