|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
|
Re: [PLUG] Easy Bash Scripting Question
|
In the message dated: Wed, 23 Dec 2009 08:32:57 EST,
The pithy ruminations from Casey Bralla on
<Re: [PLUG] Easy Bash Scripting Question> were:
=> On Wednesday December 23, 2009 8:28:01 am bergman@merctech.com wrote:
=>
=> Good point, Mark, but this script was just an example. (My script is more
=> complex and does a specific task unrelated to the question I was asking.)
Um, I don't mean to be rude, but if you're asking such an elementary question[1]
then I strongly doubt whether you should be running a "more complex"
script. Again, I'd suggest turning all the irreversible actions of the script
(cp, rm, etc.) into "echo" statements until it's fully tested.
=>
=> BTW, what does "sudo rm /* -r" do? <grin>
Um, under what OS? Under what distro or version of "rm"[2]? Depending on the
verion of "rm", it'll [try to] remove all files in the root directory, followed
by trying to remove a file name "-r" in the current directory. Or it's try to
recursively remove everything from the root directory down. Of course, without
the "-f" option, it may still fail[3] (even when run as root) on certain files
and directories.
Again, if you don't understand how things work, you won't get the results that
you expect.
Mark
[1] To be clear, there's nothing wrong with asking elementary questions
...we all need to start somewhere, and it's better to ask than not to.
[2] I don't have an embdedded machine here...how does busybox handle
options that follow the filename arguments?
[3] man chattr setfacl. Research rbac.
=>
=> >
=> > =>
=> > => for example:
=> > =>
=> > => #!/bin/bash
=> > => cp file1 file2
=> > => mkdir /directory1
=> > => cd /directory1
=> > => rm *
=> >
=> > Whoa! That's very risky....think of what happens if the "mkdir" or "cd"
=> > commands fail. I've seen developers wipe out a multi-millon dollar
=> > ecommerce site multiple times with just this kind of error. (Yes, multiple
=> > times...they assumed it was an OS or sysadmin error, and after I restored
=> > the server--multiple times--they kept running the same script...loads of
=> > fun.)
=> >
=> > Before running this script, I'd strongly recommend:
=> >
=> > changing the "rm" command to echo what it would do, as in:
=> >
=> > echo "Would do: rm *"
=> >
=> >
=> > learning how to check the return value of a command (the mkdir & cd),
=> > and how to avoid doing the following operations if the command[s]
=> > failed
=> >
=> > Mark
=> > >
=>
=> --
=>
=> Casey Bralla
=> Chief Nerd in Residence
=> The NerdWorld Organisation
=>
=> http://www.NerdWorld.org
=> ___________________________________________________________________________
=> Philadelphia Linux Users Group -- http://www.phillylinux.org
=> Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
=> General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
=>
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|