0

I am trying to execute a command after execution of a shell script. Following code is what i have tried so far:

#! /bin/bash
exec >> /tmp/foo.log

#$REPO and $AUTHOR are environmental varibles
echo "test" >> /tmp/foo.log
echo $REPO >> /tmp/foo.log
echo $AUTHOR >> /tmp/foo.log

exit 0

cd /var/www/html/websvn
php remove_commits.php $REPO $AUTHOR

The above script is not working for some reason. How can i fix this? Need your help badly.

3
  • What are you trying to do with the exec statement at the top? You haven't told it what to execute. In addition, when you run exit 0, the shell will exit; later commands will not be run. Commented Nov 25, 2013 at 5:17
  • 1
    @Saposhiente in this case, "cat >> /tmp/foo.log" is not for execution for some program. it redirects all stdout to /tmp/foo.log. so other three ">>/tmp/foo.log" is not needed. Commented Nov 25, 2013 at 5:36
  • (The cat in the preceding comment should obviously be exec.) Commented Nov 25, 2013 at 13:03

2 Answers 2

3

Assuming you want to execute the cd command and the php script, you will need to remove the exit 0. That exits the script.

Sign up to request clarification or add additional context in comments.

5 Comments

How do I execute cd command and the php script after successful execution of commands above it? Do i need to create another shell script and add cd command and the php script?
As sophishiente pointed out, check out the exec >> /tmp/foo.log. Specifically, what do you think that is supposed to do? Hint: remove that line and see if that will fix your problem.
How do you suppose the echo commands could fail? Anyway, adding set -e to the top of the script will force it to terminate in case of error.
echo will not fail. I was referencing the odd exec >> /tmp/foo.log line.
It's not odd; see @JungsuHeo's comment.
0

below code runs php after foo.sh is successful.

$ ./foo.sh && (cd /var/www/html/websvn; php remove_commits.php $REPO $AUTHOR)

exec >> /tmp/foo.log this redirect all output of following command to /tmp/foo.log. not for execution command. refer to http://wiki.bash-hackers.org/commands/builtin/exec

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.