LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-24-2004, 08:05 AM   #1
VisionZ
Member
 
Registered: Mar 2004
Posts: 58

Rep: Reputation: 15
Angry Need helpThis script erased a bunch of my files HELP


can anyone tell me why this script didnt prompt me for a CLA
or CD into the directory specified?? I,m using Cygwin for windows sdo I had to mkdir the cygdrive firrst then I ran this script in my home folder and it just started erasing emacs files and folders......Not my temporory internet files

Can someone help or tell me why it did this or give suggestions?

Code:
echo "would you like to delelte your temp internet files"
read yes

if [ $1 = yes ]
then
cd /cygdrive/c/Documents\ and\ Settings/Owner/Local\ Settings/Temporary\ Internet\ Files/

rm -rvf *

else 
echo "fine let them sit there"
exit 1

fi
 
Old 03-24-2004, 08:45 AM   #2
Nis
Member
 
Registered: Jul 2003
Location: Virginia
Distribution: Ubuntu Hoary (5.04)
Posts: 550

Rep: Reputation: 31
Instead of cd to a directory and removing files, just remove the files directly, i. e.
Code:
rm -rvf /cygdrive/c/Documents\ and\ Settings/Owner/Local\ Settings/Temporary\ Internet\ Files/*
 
Old 03-24-2004, 09:45 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,107

Rep: Reputation: 5336Reputation: 5336Reputation: 5336Reputation: 5336Reputation: 5336Reputation: 5336Reputation: 5336Reputation: 5336Reputation: 5336Reputation: 5336Reputation: 5336
Whats a CLA? Command line argument? There isn't a prompt for command line arguments. Command line arguments need to be on the command line with the application name.

app_name arg1 arg2 etc. etc...

Did the script stop and wait with the read statement for you to enter something?

Also the if statement should be like for a command line argument:
if [ $1 = "yes" ] then

If you are trying to use the read statement then

if [ $yes = "yes" ] then

Your if statement is evaluating to true because you did not enter a command line argument and yes does not evaluate to anything.

I would guess that something is wrong with your cd statement. Since your current working directory was your home directory the rm will delete everything.

BTW hindsight is always 20-20 but try testing your script in some test directory where you can not do any damage.

Last edited by michaelk; 03-24-2004 at 09:47 AM.
 
Old 03-24-2004, 10:38 AM   #4
thehundredthone
Member
 
Registered: Nov 2003
Distribution: Fedora Core 1
Posts: 76

Rep: Reputation: 15
if i'm right then $1 is the first argument after the command's name. that's the only way it can delete your files. read yes means it's reading the variable yes; but it isn't using it anywhere else.
 
Old 03-24-2004, 11:19 AM   #5
trade14u
LQ Newbie
 
Registered: Mar 2004
Posts: 14

Rep: Reputation: 0
Try this:

#!/bin/bash

TEMP_DIR="/cygdrive/c/Documents\ and\ Settings/Owner/Local\ Settings/Temporary\ Internet\ Files/"

echo "would you like to delete your temp internet files?"
read yes

case "$yes" in

[Yy]) rm -frv $TEMP_DIR;;
*) echo "fine let them sit there";
exit 1;;

esac


if you use your method, I would ensure you actually cd'd to the directory by checking the return value of the statement before you delete stuff. Your script deleted the stuff ASSUMING you were in the directory. Check the success two ways:

1. Use $? (the return code of a statement)
cd /tmp
if [ $? -eq 0 ] then
rm -fr *
fi

2. Use &&
cd /tmp && rm -fr *

The statement after the && will execute if the first statement is successful.

Two links you MUST have:

Scripting tutorials with TONS of samples:

http://www.tldp.org/HOWTO/Bash-Prog-...OWTO.html#toc7
http://www.tldp.org/LDP/abs/html/
 
Old 03-24-2004, 11:30 AM   #6
guygriffiths
Member
 
Registered: Jun 2003
Location: Reading, UK
Distribution: Debian 3.0, LFS
Posts: 524

Rep: Reputation: 37
I was about to add te very same thing, but with this method of checking:

if `cd /path/to/change/to`
then
do things
else
echo "Can't change dir"
fi

Also, trade14u, I played your Russian Roulette game, but it just kept saying "You live", and one time it didn't do anything, and then my pc crashed and it won't reboot to Linux.
 
Old 03-24-2004, 11:51 AM   #7
Redeye2
Member
 
Registered: Feb 2004
Posts: 489

Rep: Reputation: Disabled
Hmmm if you're kidding, then you just erased your whole linux root
 
Old 03-24-2004, 11:55 AM   #8
guygriffiths
Member
 
Registered: Jun 2003
Location: Reading, UK
Distribution: Debian 3.0, LFS
Posts: 524

Rep: Reputation: 37
WHAT!!!!!

No, I'm kidding really.
 
Old 03-24-2004, 11:56 AM   #9
Redeye2
Member
 
Registered: Feb 2004
Posts: 489

Rep: Reputation: Disabled
lmao, I knew but it was a good laugh to read
 
Old 03-25-2004, 12:06 AM   #10
VisionZ
Member
 
Registered: Mar 2004
Posts: 58

Original Poster
Rep: Reputation: 15
thanks for all of your help, unfortunately none of your examples worked,

I tried the TEMP_DIR one, no avail? no output

After trying my script instead of erasing I tried

echo $PWD

it still says home/owner

and I dont know why????
I know I messed up it wasnt suppposed to have a CLA and my if variable was wrong i changed it to
read answer
if [ $answer = yes ]
then
/temp && rm -fr *
but that doesnt seem to want to work either??

Any ideas why its not CDing to that directory?????
Thanks for all the help
 
Old 03-25-2004, 12:13 AM   #11
VisionZ
Member
 
Registered: Mar 2004
Posts: 58

Original Poster
Rep: Reputation: 15
when I tried && rm -rvf *
it started erasing files but I dont know where????
It said this

removing 'A3GNORSN/Showletter[10]'
over and over and over a bunch of times

what is this file??? If you are right Trade14u then didnt it check with && to make sure it CD'ed to that directory??
 
Old 03-25-2004, 04:16 AM   #12
guygriffiths
Member
 
Registered: Jun 2003
Location: Reading, UK
Distribution: Debian 3.0, LFS
Posts: 524

Rep: Reputation: 37
Quote:
I know I messed up it wasnt suppposed to have a CLA and my if variable was wrong i changed it to
read answer
if [ $answer = yes ]
then
/temp && rm -fr *
but that doesnt seem to want to work either??
Is this code copied and pasted? If so then your problem is that you put
/temp
instead of
cd /temp

Although it still shouldn't have worked, since /temp should return negative since it's not a valid command. I assume you're using bash? Do echo $SHELL to find out.
 
Old 03-25-2004, 10:02 AM   #13
thehundredthone
Member
 
Registered: Nov 2003
Distribution: Fedora Core 1
Posts: 76

Rep: Reputation: 15
try:

#!/bin/bash

TEMP="/path/to/tempdir"

echo do you want to delete temp files
read ans

case $ans in

[Yy]) if `cd $TEMP`
then
echo deleting files
rm -rvf *
else
echo Cannot change directory
exit
fi
;;
*) echo OK let them be
;;
esac

Last edited by thehundredthone; 03-25-2004 at 10:09 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bookmarks erased habala Linux - General 3 01-29-2005 10:13 PM
External hd keeps getting erased. Schopenhauer101 Linux - Hardware 1 01-15-2005 06:23 PM
Need to chown a bunch of remote files. Kbear? $ftp? asktoby Linux - Software 0 12-06-2004 10:27 AM
Erased files by mistake Linucec Linux - General 5 05-21-2004 08:12 PM
Help! Have I Erased My Bios? ixus_123 Linux - Newbie 5 04-11-2004 07:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration