Accidently deleted /usr contents.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Accidently deleted /usr contents.
# 8  
Old 01-30-2013
This is why whenever I run rm -rf from a script, my first run is ALWAYS:
Code:
...
#rm -rf $something
echo "we will be removing: $something"
...

i.e. initially comment out the rm and have it echo what we'll be removing instead. If it looks sane, then go ahead and uncomment the rm.

Another lesson here - backups - but you have probably heard enough about that already...
This User Gave Thanks to zazzybob For This Post:
# 9  
Old 01-30-2013
Quote:
Originally Posted by chacko193
If that was the case, then all files in /usr should have been deleted.But some files were not deleted,only a few.
In post #1 it says "most of my files in /usr got deleted", not a few. I assumed you perhaps had interrupted the script in the process..
# 10  
Old 01-30-2013
Quote:
Originally Posted by Corona688
Yikes. Difficult to say without knowing what find found, but a path name with spaces in it may cause unintended splitting whenever unquoted. /path/with /usr/ would split into '/path/with' and '/usr/' for instance.

Why this script was running as root is another good soul-searching question. Preventing program bugs from getting too out of control is one reason file permissions exist, but root bypasses all that.
Quote:
Originally Posted by RudiC
You were using find to get a list of all .audit files in /var, but after that, you ran ls in the working directory that may have been pointing to somewhere else (i.e. to /usr?), got the oldest file there and rmed it with the -force option. Anyhow, it should have removed just one file, unless you ran it repeatedly to remove nearly the entire /usr dir.

Your second code snippet is far safer here...

But the script would have ran only a few times,probably less than ten,before I noticed the files missing.So how come more than 300 files were deleted from /usr/bin alone and some directories in /usr were removed altogether.
# 11  
Old 01-30-2013
How many files were left in /usr/bin ? Is it possible that some files were (re-)installed in /usr/bin after a previous removal? Then the script could have been run with the current directory set to /usr, since it was trying to remove the oldest entry, even directory trees not just files...

Last edited by Scrutinizer; 01-30-2013 at 03:02 AM..
# 12  
Old 01-30-2013
Quote:
Originally Posted by Scrutinizer
In post #1 it says "most of my files in /usr got deleted", not a few. I assumed you perhaps had interrupted the script in the process..
I had nothing to with the execution of the script,it was executed by audomon daemon.

Quote:
Originally Posted by Scrutinizer
How many files were left in /usr/bin ? Is it possible that some files were (re-)installed in /usr/bin after a previous removal? Then the script could have been run with the current directory set to /usr, since it was trying to remove the oldest entry, even directory trees not just files...
I don't think it would have reinstalled anything,because I don't think any provsion exists to do so.
Only bin,lbin,sbin and lib were present in /usr after deletion took place and most files were missing from them too.In /usr/bin I think only 4 files were left.I think they were view,remsh and other two startin with 'r'.
# 13  
Old 01-30-2013
Anyone who runs a script as root which deletes files is asking for trouble.

So, when the OP asks "what went wrong?", the answer is pretty straight forward.

The OP ran a script that removes files (as the superuser!) without testing the script first. It's that simple.

How do you test it?

Well, when the script runs, instead of removing the files, you simply write the files that would be deleted to a file. Then, you examine the file with the output of "files and directories that would have been deleted" and make sure the script does what you want. If all is OK, then enable the script to actually work (delete the files).

Never, ever, run a script that deletes files (especially as root) without testing first and confirming the script is working as intended.

Edit: Note that ZB recommends a similar approach in his reply above.
# 14  
Old 01-30-2013
Quote:
Originally Posted by chacko193
I had nothing to with the execution of the script,it was executed by audomon daemon.



I don't think it would have reinstalled anything,because I don't think any provsion exists to do so.
Only bin,lbin,sbin and lib were present in /usr after deletion took place and most files were missing from them too.In /usr/bin I think only 4 files were left.I think they were view,remsh and other two startin with 'r'.
I was not suggesting that the script might have reinstalled anything, but enquiring about the possibility that somebody else of some other process could have been installing or reinstalling something in /usr/bin after the script had previously removed the directory (perhaps even as a response to it, for example some form of configuration management)

Last edited by Scrutinizer; 01-30-2013 at 03:30 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Contents deleted from /var/sadm

Hi, Somebody/somebody removed all contents /vat/sadm on Solaris 10 Sparc box. As of now server is up and running. There is no backup for this server. If we copy contents from another equivalent server, can it work ? We don't know if it will be fixed by booting form DVD also. Any suggestions? (4 Replies)
Discussion started by: solaris_1977
4 Replies

2. BSD

FreeBSD: /usr/bin/ld not looking in /usr/local/lib

I'm not sure if this is the default behavior for the ld command, but it does not seem to be looking in /usr/local/lib for shared libraries. I was trying to compile the latest version of Kanatest from svn. The autorgen.sh script seems to exit without too much trouble: $ ./autogen.sh checking... (2 Replies)
Discussion started by: AntumDeluge
2 Replies

3. BSD

NetBSD Accidently deleted crontab for root

Someone can told me where from get the default crontab settings of root for NetBSD 6.0 please :) ### SOLVED ### The default crontab rules are in etc.tgz /var/cron/tabs/root # $NetBSD: crontab,v 1.15 2002/11/27 15:09:17 perry Exp $ # # /var/cron/tabs/root - root's crontab for NetBSD #... (0 Replies)
Discussion started by: batence
0 Replies

4. AIX

Which files can be deleted in /usr in an aix hacmp node?

Hi Can ony one advise which files can be deleted in /usr in an aix hacmp node ? Im new to aix and Im not sure which files can be deleted ? #df -g /usr Filesystem GB blocks Free %Used Iused %Iused Mounted on /dev/hd2 7.00 1.00 86% 67013 22% /usr ... (4 Replies)
Discussion started by: samsungsamsung
4 Replies

5. Solaris

Accidentally deleted s. link /usr/lib/secure/s8_preload.so.1

I have accidentally deleted the sim link: /usr/lib/secure/s8_preload.so.1 -> /.SUNWnative/usr/lib/brand/solaris8/s8_preload.so.1 and now I can't do almost anything in my Solaris 8 container. I still have an open session to the machine. I can not create the link again because trying to run:... (1 Reply)
Discussion started by: qwertysas
1 Replies

6. Solaris

How do I link ld in /usr/ucb/ to /usr/ccs/bin?

Hi all, below is the problem details: ora10g@CNORACLE1>which ld /usr/ucb/ld ora10g@CNORACLE1>cd /usr/ccs/bin ora10g@CNORACLE1>ln -s /usr/ucb/ld ld ln: cannot create ld: File exists ora10g@CNORACLE1> how to link it to /usr/ccs/bin? (6 Replies)
Discussion started by: SmartAntz
6 Replies

7. UNIX for Dummies Questions & Answers

deleted /usr

I accidentally deleted the usr on/. How can I start the server again? (5 Replies)
Discussion started by: rahmantanko
5 Replies

8. Solaris

Directory should not be deleted, But the contents can be

Hi Guys, I have an user's home directory set to /home/A And A contains the following directories B & C Is there some way in solaris by which i can prevent the directories B and C from getting deleted by the user but the contents of the directories B & C can be deleted ? Also i have... (2 Replies)
Discussion started by: localhost
2 Replies

9. UNIX for Dummies Questions & Answers

crontab deleted accidently

I issued crontab -r accidently instead of crontab -e..n the crontab file got deleted.. is there a way to retrive it?:-( thank you:( (3 Replies)
Discussion started by: unisam
3 Replies
Login or Register to Ask a Question