Accidently deleted /usr contents.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Accidently deleted /usr contents.
# 1  
Old 01-29-2013
Accidently deleted /usr contents.

Hi

I have the following code which was supposed to clean up a directory when the number of files in that directory exeeded 2.The code is given below.

Code:
 
#!/usr/bin/ksh
dir_num=`/usr/bin/find /var/.audit -type d | /usr/bin/wc -l`
if [ $dir_num -gt 2 ]
then
 oldest_file=`/usr/bin/ls -1t | /usr/bin/tail -1`
 /usr/bin/rm -rf $oldest_file
fi

When executed the above code something bad happened.Apparantly most of my files in
Code:
/usr

directory got deleted.Can anyone tell me how it happened?

I have the modified code:
Code:
 
 
#!/usr/bin/ksh
dir_num=`/usr/bin/find /var/.audit -type d | /usr/bin/wc -l`
if [ $dir_num -gt 2 ]
then
 oldest_file=`/usr/bin/ls -1t /var/.audit/ | /usr/bin/tail -1`
 /usr/bin/rm -rf /var/.audit/$oldest_file
fi

Is there any way to recover those file?

Thanks in advance...
# 2  
Old 01-29-2013
Yes, you can recover from your system backup.
# 3  
Old 01-29-2013
Quote:
Originally Posted by Neo
Yes, you can recover from your system backup.
You see,I don't have a backup.What I'm doing now is copying all those files from another server with the same configuration.

Is there any other way?

---------- Post updated at 09:03 AM ---------- Previous update was at 09:00 AM ----------

What I really want to know is how it happened.How did all those files got deleted in ther first place?
# 4  
Old 01-29-2013
Quote:
Originally Posted by chacko193
You see,I don't have a backup.
Yikes.
Quote:
What I really want to know is how it happened.How did all those files got deleted in ther first place?
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.
# 5  
Old 01-29-2013
Quote:
Originally Posted by chacko193
Code:
 
#!/usr/bin/ksh
dir_num=`/usr/bin/find /var/.audit -type d | /usr/bin/wc -l`
if [ $dir_num -gt 2 ]
then
 oldest_file=`/usr/bin/ls -1t | /usr/bin/tail -1`
 /usr/bin/rm -rf $oldest_file
fi

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...
These 2 Users Gave Thanks to RudiC For This Post:
# 6  
Old 01-29-2013
$oldest_file could also have contained a directory entry. Maybe the script was executed while in the root directory and /usr happened to be the oldest entry..

Last edited by Scrutinizer; 01-29-2013 at 12:42 PM..
# 7  
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.
Well find was intented to return a number;initially 2 and then 3 on the next run,but never more than 3.

And another intresting fact is that the $oldeest_file sholud only have the filename and not any path.
The script was supposed to be automatically executed by the audomon daemon when the audit trail was swiched to another file.So I have no idead fom where the script was run,but I think the script would hav run with a UID of 0 and thus all the problem.

---------- Post updated at 01:41 AM ---------- Previous update was at 01:37 AM ----------

Quote:
Originally Posted by Scrutinizer
$oldest_file could also have contained a directory entry. Maybe the script was executed while in the root directory and /usr happened to be the oldest entry..
If that was the case, then all files in /usr should have been deleted.But some files were not deleted,only a few.
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