[NTLUG:Discuss] Linux script question
Pervaz Allaudin
pervaz at att.net
Mon Jun 16 20:20:35 CDT 2003
I appreciate the concern of both of yous; I do have the source in a zip
form the opensource so I can bring it back if needed.
I have experience in the other OS and have done my stupi... eh hum..
experience giving mistakes.
pervaz
Bug Hunter wrote:
>On Mon, 16 Jun 2003, Rusty Haddock wrote:
>
>
>
>>Bug Hunter wrote:
>>
>>
>snip> >> >
>
>
>> >
>> > for a single file:
>> >
>> > sed /oldtext/newtext/ filename > filename.newfile
>> > rm -f filename
>> > mv filename.newfile filename
>> >
>> >
>> >in bash
>> >
>> > for i in /dirname/*
>> >do
>> > sed /oldtext/newtext/ $i > $i.newfile
>> > rm -f $i.newfile
>> > mv $i.newfile $i
>> >done
>>
>>Be careful here!!! I see two problems here:
>> 1) Why are you nuking the .newfile you just created???
>> Just delete the 'rm' command.
>>
>>
>
> yep.
>
>
>
>
>> 2) If the 'sed' script fails you're still gonna nuke your
>> old files!!! How would 'sed' fail? Oh, a full file
>> system for one way. There are others. "Been there,
>> lost that!" One of the better things to do is to join
>> the 'mv' to the 'sed' with a '&&'. This way, if the
>> 'sed' fails you don't do the 'mv'. For example:
>>
>> sed /oldtext/newtext/ $i > $i.newfile && mv $i.newfile $i
>>
>>
>>
> good idea
>
>
>
>
>> Remember that the SHELL is the one who will create the
>> .newfile, not the 'sed' command. It is created before
>> the 'sed' program is even run -- it has to be otherwise
>> 'sed's stdout won't be connected to anything.
>>
>> > This was given to me by a fellow named Richard a while back. :)
>>
>>Be caseful what Richard tells you for now on. :-) Yes, it'll work
>>(well, remove the 'rm' like) 99.9% of the time. Alas, 0.1% of the
>>time it will lose what you spent 99.9% of the time creating! :-(
>>
>>
>>
>
> Well, a loaded gun in the wrong hands.....
>
>
> I always make a copy of the directory and run it on the copy until I'm
>happy. Then I move the original to a backup directory, and move the copy
>to the original, if possible. (sometimes a reboot or restart of the
>demon is required.)
>
> Discretion is the better part of system administration. Or is that
>valor?
>
> I had *assumed* intelligence on the other side. Also had assumed that
>if they had not been there, done that, they would soon learn and never do
>it twice. Or in my case, the third time is the charm. <grin>
>
>bug
>
>
>
>
>
>_______________________________________________
>https://ntlug.org/mailman/listinfo/discuss
>
>
>
More information about the Discuss
mailing list