1

I am trying to use Shell_exec to a run a script which is dynamically created and stored in a php variable. Here is the script so far.

{ curl -fsS --retry 3 https://hc-ping.com/same-unique-id-here ; \
echo "name.of.php.file.here STARTED for id # $state_id" ; \
php "/path/to/my.file.php" -i 2 -h prod 2>&1 | tee -a /path/to/log/files/my.file.log || \
curl -fsS --retry 3 https://hc-ping.com/same-unique-id-here/fail ; \
echo "name.of.php.file.here ENDED for id # $state_id with Exit Code $?" ; \
curl -fsS --retry 3 https://hc-ping.com/same-unique-id-here ; } 2>/dev/null >/dev/null &

My first problem is I only want to execute the last line

curl -fsS --retry 3 https://hc-ping.com/same-unique-id-here

if the

php "/path/to/my.file.php" -i 2 -h prod 2>&1 | tee -a /path/to/log/files/my.file.log

is successful. How do I modify the script to do that?

My second question, is this how I print the exit code at the end of a echo?

echo "name.of.php.file.here ENDED for id # $state_id with Exit Code $?"
0

I was hoping for more interaction on this question. I ended up using a variable to control what was executed. Here is the code.

{ unset -v failcode ; failcode="0" ; curl -fsS --retry 3 https://hc-ping.com/same-unique-value ; \
echo "\n$(TZ="America/New_York" date +"%m-%d-%Y %H:%M:%S %Z") my.process.name.php STARTED for id # 2" ; \
php "/path/to/my/php/script.php" -i 2 -h lab || failcode="1" ; \
echo "\n$(TZ="America/New_York" date +"%m-%d-%Y %H:%M:%S %Z") my.process.name.php ENDED for id # 2 with Exit Code $failcode" ; \
[ "$failcode" == "1" ] && curl -fsS --retry 3 https://hc-ping.com/same-unique-value/fail ; \
[ "$failcode" == "1" ] && exit 1 ; \
curl -fsS --retry 3 https://hc-ping.com/same-unique-value ; } \
2>&1 | tee -a /path/to/my/log/file.log 2>/dev/null >/dev/null &

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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