Re: Writing scripts in Linux
- From: Rich Leitner <Rich@xxxxxxxxxxxxx>
- Date: Mon, 22 Oct 2007 05:33:59 GMT
On Mon, 22 Oct 2007 01:05:22 +0000, Bonsai Bonanza wrote:
Bit Twister wrote:
On Sun, 21 Oct 2007 23:02:58 GMT, Rich Leitner wrote:
Okay, I'm a bit new to shell scripting but learning. What's wrong with
writing a shell script as root so long as the script does not have
root privileges itself?
Shell scripts execute with the privs of the user running them.
If you are writing a script as root, and testing it as root, you need to
be very careful, that is all.
here is a VERY stupid example (please DO NOT run it as root - it will
destroy your machine!!!!!!!!!!)
#!/bin/sh
TOPDIR="/"
JUNKDIR1="junk-dir1"
JUNKDIR2="junk-dir2"
echo cleaning out junk-dir1 and junk-dir2 rm -rf $TOPDIR/$JUNKDIR1/*
rm -rf $TOPDIR/$JUNK_DIR2/*
I WANTED to have the script delete everything under "/junk-dir1" &
"/junk-dir2"
Unfortunately, on the second rm line, I wrote: rm -rf
$TOPDIR/$JUNK_DIR2/*
when I MEANT to write
rm -rf $TOPDIR/$JUNKDIR2/*
The outcome is the command
"rm -rf ///*" is run (which is the same as "rm -rf /*"
This command deletes everything on your hard drive, and your system will
stop working... for you, and everyone else.
If you run that script as a regular user, it will start spewing messages
like:
rm: cannot remove directory `bin': Is a directory
yes, eventually it will recursively works its way down to your home
directory, and delete everything there... which would suck... but the
machine is still up and running fine for everyone else.
The "root" account can cause GLOBAL mistakes. A regular user can only
cause LOCAL mistakes.
Okay, that makes good sense. I have a couple old experimental machines
that I fool with, and I often sign on as root (against the conventional
wisdom, I know!) because it's easier and I'm lazy, but I don't really
worry about mucking them up. I'll keep that in mind for any important
machines. Thanks...
Rich
.
- References:
- Writing scripts in Linux
- From: Cisco_King
- Re: Writing scripts in Linux
- From: Dan Espen
- Re: Writing scripts in Linux
- From: Rich Leitner
- Re: Writing scripts in Linux
- From: Bit Twister
- Re: Writing scripts in Linux
- From: Bonsai Bonanza
- Writing scripts in Linux
- Prev by Date: Re: Writing scripts in Linux
- Next by Date: Fedora Core 6 Install
- Previous by thread: Re: Writing scripts in Linux
- Next by thread: Re: Writing scripts in Linux
- Index(es):
Relevant Pages
|