I have written a shell script checklick.sh on my CentOS box with the following content:


# description: check link through rtmpdump

. /etc/rc.d/init.d/functions

"$DUMPUTIL" -B 1 -r "$1" -o /tmp/rtmp-checker.log && echo_success || echo_failure

and executed by

./checklink.sh rtmp://tv2.globisoft.net/live/tv2

Now, from the following output:

enter image description here

I need to know how to force exit the script when the log prints ERROR: RTMP_ReadPacket, failed to read RTMP packet header because I'm calling the script from PHP exec native function and is waiting forever for the exit code but the script does not return the exit code.

  • Did you write exit 1 or the exit code that you want in the function echo_failure? – Hastur Dec 1 '14 at 0:55

How about testing each line of the command output?


while read -r line; do
  echo "$line"

  if [[ "$line" == "TEST" ]]; then
done < <(cat testfile)

The above reads the output from a given command (in this case "cat testfile"), then echos the result. It checks for a line that equals "TEST" and exits if it finds a match.

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.