By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,706 Members | 1,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,706 IT Pros & Developers. It's quick & easy.

Execution of bash script inside a bash script

m6s
P: 55
Hello to all,
I have this code :

echo "$SERVICE is not running" >> /var/log/messages
START=$(date +%s)
exec '/home/m6s/projects/services/runtest.sh'
END=$(date + %s)
echo $END
DIFF=$(( $END - $START ))
echo $DIFF
echo "$SERVICE, took $DIFF seconds" >> /var/log/messages

It takes the time it started, it tries to executed the runtest.sh, and then it is supposed to return back to the main program after the execution take the END, calculate the DIFF and report the result to /var/log/messages.

But when the second program terminates, it terminates entire script. At least is seems so. What is wrong with this snippet?

Thank you in advance...
May 20 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 849
That's because exec kills the current process and replaces it with the other. Use backticks to do this, eg `sh scriptname.sh`. Using backticks also allows you to capture any input that comes from the commands inside.
May 20 '08 #2

m6s
P: 55
m6s
That's because exec kills the current process and replaces it with the other. Use backticks to do this, eg `sh scriptname.sh`. Using backticks also allows you to capture any input that comes from the commands inside.
You were right, wrong of me to use this exec.It returns now back to the script, but END has never the variable of date... ?!? So diff takes only the -START!!
May 20 '08 #3

m6s
P: 55
m6s
You were right, wrong of me to use this exec.It returns now back to the script, but END has never the variable of date... ?!? So diff takes only the -START!!
It was a space in +s :-)
Ok, thank you very much for the help about exec.
May 20 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.