why test ret-val of EACH cmd (example!):

D

David Combs

Just for use when warning people to test return-values,
here's this post I just saw on comp.unix.solaris:


| comp.unix.solaris #503931 (367 + 1662 more) | | \-(1)--(1)+-(1)
| Newsgroups: comp.unix.programmer,comp.unix.solaris | | \-(1)
| [1] Re: implicit -e in Solaris /bin/sh on cd? | \-(1)--(1)
| From: Casper H.S. Dik <[email protected]> \-(1)+-(1)
| Date: Sat Apr 16 16:39:29 EDT 2005 |-(1)
| Lines: 47 \-[1]
|
|
| >Henry Townsend wrote:
| >> % /bin/sh -c "cd /xxxx; /bin/pwd"
| >> On Linux, this gives an error for the cd and thn proceeds to run
| >> /bin/pwd (as it should IMHO):
|
| >not so good if the command is supposed to run in /xxxx, think of
|
| >cd /xxxx; rm -rf *
|
|
| Indeed; one day a rather distraught Sun Service person turned up
| at my desk, fearing that one of his customers systems had gotten hacked.
| He brought with him a disk.
|
| I examined this disk; I was particularly worried about hacks because the
| system didn't run anyting much at al, nothing from inetd anyway.
|
| Then I found that they had a ksh script which went as follows:
|
|
|
| for dir in <list of dirs>
| do
| cd $dir
| find . -mtime -30 -exec rm {} \;
| done
|
| Unfortunately, this was run as root, the first directory didn't
| exist (had in fact been removed just prior to the incident) and
| the find proceeded to remove all files until the point it removed
| /usr/lib/ld.so.1; then it stopped removing stuff but rather started
| logging errors.
|
| In the end I managed to recover the list of file printed by find
| to tmpfs (/tmp/cron..*).
|
| It was a "ksh" script; had it been a "sh" script it would not
| have failed in this manner.
|
| Casper
| --
| Expressed in this posting are my opinions. They are in no way related
| to opinions held by my employer, Sun Microsystems.
| Statements on Sun products included here are not gospel and may
| be fiction rather than truth.
| End of article 503931 (of 505348) -- what next? [npq]
|

(Now watch me go off and do that very thing!)

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top