In Bourne Shell (only 3 programs, but that's cuz I'm lazy):
#!/bin/sh -x FILE1=$1 FILE2=$2 FILE3=$3 FILE4=$4 prog1.pl $FILE1 $FILE2 STATUS=$? if [ $STATUS != 0 =; then set +x echo "Belch in prog1.pl: $STATUS" exit $STATUS fi prog2.pl $FILE2 $FILE3 STATUS=$? if [ $STATUS != 0 =; then set +x echo "Belch in prog2.pl: $STATUS" exit $STATUS fi prog3.pl $FILE3 $FILE4 STATUS=$? if [ $STATUS != 0 =; then set +x echo "Belch in prog3.pl: $STATUS" exit $STATUS fi
Or, if the intermediate file names don't matter, and the intermediate files aren't too big:
#!/bin/sh FILE1=$1 FILE2=/tmp/file.$$.1 FILE3=/tmp/file.$$.2 FILE4=$2 SAFE=/path/to/save_file.$$ prog1.pl $FILE1 $FILE2 STATUS=$? if [ $STATUS != 0 =; then set +x echo "Belch in prog1.pl: $STATUS" exit $STATUS fi prog2.pl $FILE2 $FILE3 STATUS=$? if [ $STATUS != 0 =; then set +x echo "Belch in prog2.pl: $STATUS" mv $FILE2 $SAVE exit $STATUS fi prog3.pl $FILE3 $FILE4 STATUS=$? if [ $STATUS != 0 =; then set +x echo "Belch in prog3.pl: $STATUS" mv $FILE3 $SAVE exit $STATUS fi #Clean-up temp files /bin/rm -f $FILE1 $FILE2 STATUS=$? if [ $STATUS != 0 =; then set +x echo "Error removing temporary files" echo "$FILE1 and" echo "$FILE2." echo "Please clean-up by hand" exit $STATUS fi
That answers your original question. That having been said, the answers given above are much better ideas. This way does give you a couple of break points so that if prog4.pl chokes, you still have the output from prog3.pl and a place to start debugging prog4.pl

Hope this helps, thor


In reply to Re: UNIX shell scripts + pipes by thor
in thread UNIX shell scripts + pipes by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.