Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question is an exact duplicate of:

MAILTO=""
*/10 * * * *  /bin/bash /var/www/sym_monitor/sym_start.sh > /var/www/migrate/root_start.txt 2>&1
*/10 * * * *  /bin/bash /var/www/sym_monitor/stop.sh > /var/www/migrate/root_stop.txt 2>&1

Both these are jobs inside cron running at 10 min interval @17:30 second one starting and 1735 first one starting avoiding the killing of first job by second before it actually started.

First script consist of the following code

#!/bin/bash
value=$(</var/www/sym_monitor/man.txt)


if [ "$value" == "true" ]; then

     ps -ef|grep sym |grep -v grep |awk '{ print $2 }'|sudo  xargs kill -9;

fi

Second script consists of the following code.

#!/bin/bash
value=$(</var/www/sym_monitor/man.txt)

if [ "$value" == "true" ]; then

sleep 30;
cd /var/www/symmetric-ds-3.1.6/bin;
(sudo ./sym --port 8082 --server);

fi

The problem is when I run both the scripts unfortunately sym_start.sh is not executing. But when I remove the stop.sh and manually run the stop script then the only script in the cron is executing properly. why thus this happen? any idea?

share|improve this question

marked as duplicate by Dennis, BBlake, Canadian Luke, 8088, Renan Feb 25 '13 at 17:42

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.

    
I'm not sure what you meant in the first paragraph, but it seems to me that you're thinking the 2 jobs are executed at different times. It is not the case. They are executed both at the same time. –  m4573r Feb 25 '13 at 13:30
    
This is still the same issue as in Command not executing inside shell script?. Instead of posting a new question, you can edit it to incorporate further information. –  Dennis Feb 25 '13 at 13:47

1 Answer 1

Your crontab description shows the will both be run at the same time. Your start script has a 30sec sleep in it, I imagine to try and help with ordering. If you want to run the two jobs sequentially you should rewrite it as a single script that does it in the order you want. Maybe something like this:

#!/bin/bash

value=$(</var/www/sym_monitor/man.txt)

if [ "$value" == "true" ]; then
    ps -ef|grep sym |grep -v grep |awk '{ print $2 }'|sudo  xargs kill -9;
fi
sleep 30;
if [ "$value" == "true" ]; then
    cd /var/www/symmetric-ds-3.1.6/bin;
    (sudo ./sym --port 8082 --server);
fi
share|improve this answer
    
Thanks for the reply slushpupie, Unfortunately that is actually my initial script. That is not working for me I mean in this case also the second script(sudo ./sym --port 8082 --server) is not working. So I break it up and trying to run as 2 scripts. –  user1597811 Feb 26 '13 at 4:23

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