Yesterday a 20 line shell script caught a race condition in one of software I work on. Our best engineers looked at the problem, a vendor case was filed, and there was thoughts of automatically restarted the application to fix the issue at hand.

In the end, a 20 line shell script to strace for file operations continuously provided the needed visibility into the issue at hand.

Update: The shell script.

The shell script itself, though trivial, is owned by the company I work for, but the basic concept was as follows:

#!/bin/bash

# loop forever
while sleep 60
do
pid=$(ps -ef | grep application | egrep -v grep | awk ‘{print $2}’)
if [[ -n $pid ]]
then
outfile=strace-application-$(date +%Y%M%d-%H:%M:%S).out.gz
strace -tt -f -e trace=file -p $pid 2>&1 | gzip -c > $outfile
fi
done

8 Responses to “Shelling scripting is a necessary skill”

  1. Ben Says:

    Snippet of the script?

  2. Brock Noland Says:

    There you go…

  3. James Says:

    What is the purpose of the “while sleep 60″ line?

  4. Brock Noland Says:

    Just so if the strace fails, the script does not go berserk. A “safety” mechanism of sorts.

  5. Коля Says:

    Прив

    Спасибо

  6. Сигизмунд Says:

    Феоктист…

    2106 тюнинг

  7. Костя Says:

    СПС.

    Я тут

  8. Сергей Says:

    http://rel” rel=”nofollow”> Спасибо,…

    Хотя новость уже читал…

Leave a Reply

If Wordpress eats your comment (shell output, loops, ex..) email the text to me.