Re: Writing scripts in Linux
- From: Bonsai Bonanza <nntp@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 22 Oct 2007 01:05:22 GMT
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.
--
Alexander N. Spitzer
Bonsai Bonanza
http://www.BonsaiBonanza.com
.
- Follow-Ups:
- Re: Writing scripts in Linux
- From: Rich Leitner
- Re: Writing scripts in Linux
- 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
- Writing scripts in Linux
- Prev by Date: Re: Writing scripts in Linux
- Next by Date: Re: Writing scripts in Linux
- Previous by thread: Re: Writing scripts in Linux
- Next by thread: Re: Writing scripts in Linux
- Index(es):
Relevant Pages
|