LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 08-16-2006, 12:05 PM   #1
AndrewBS42
LQ Newbie
 
Registered: May 2006
Posts: 7

Rep: Reputation: 1
RH Enterprise Linux3: Rebuild /usr/bin?


We're running RedHat Etnerprise Linux3 on a Dell box.
Last week, somebody deleted the /usr/bin directory.
Unfortunately, we have no backup of that directory.
We do have the original installation media.
Is there a way to repair or rebuild the /usr/bin directory from that without actually reformatting the drives and starating from scratch?

All replies welcome, please email direct
AndrewBS42@hotmail.com
 
Old 08-16-2006, 01:12 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Is there a way to repair or rebuild the /usr/bin directory from that without actually reformatting the drives and starting from scratch?
Why not?:
Code:
cd $TEMP
rpm -qa --dump|grep /usr/bin|awk '{print $1}'|while read bin; do
rpm -q --whatprovides "$bin"; done|sort|uniq|while read name; do
find /mountpoint -type f -name ${name}\*.rpm|head -1|while read rpm; do
rpm2cpio $rpm > ./${name}.cpio && \
cat ./${name}.cpio|cpio -ivd --no-absolute-filenames "./usr/bin/*"
rm -f ./${name}.cpio; done; done; done
Now your binaries are in $TEMP/usr/bin. To help you install them and change ownership and access rights you can generate them from the RPM database as well:
Code:
rpm -qa --dump|grep /usr/bin|awk '{print $1, $5, $6, $7}'|while read bin p o g; do 
[ "${p:2:1}" = "2" ] && d="#symlink"; echo "${p:3} $o $g $bin ${d}"; done
Using output to actually install the binaries "is left as an exercise to the reader".


All replies welcome, please email direct
Simple rule, no exceptions:
Ask question here, get answer here.

Last edited by unSpawn; 08-16-2006 at 01:14 PM. Reason: //Have keybd, can't type
 
Old 08-16-2006, 01:36 PM   #3
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
I just wanted to try this out, so I deleted my /usr/bin and ran your script.
I get an error
syntax error near unexpected token 'done'
 
Old 08-16-2006, 05:55 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I just wanted to try this out, so I deleted my /usr/bin
Neat!


I get an errorsyntax error near unexpected token 'done'
Bummer.

Which "done"? You did replace the "/mountpoint" placeholder with the directoryname where your rpms reside in? Can you run the script as "sh -x scriptname 2>&1|scriptname.log" and post the contents here (please skip posting repeats)? Thanks.
 
Old 08-16-2006, 07:46 PM   #5
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
error on this line.
rpm -q --whatprovides "$bin"; done|sort|uniq|while read name; do

I changed the mountpoint to /mnt/Fedora/RPMS, thats my dvd.
 
Old 08-16-2006, 08:27 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
error on this line.
rpm -q --whatprovides "$bin"; done|sort|uniq|while read name; do

Hmm. Try this:
Code:
]$ set -xe
]$ rpm -qa --dump|grep /usr/bin|awk '{print $1}'|while read bin; do 
rpm -q --whatprovides "$bin" >/dev/null || echo "\"${bin}\""; done
I ran it on two boxen and nothing weird came up.
 
Old 08-16-2006, 08:40 PM   #7
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
ok now the error comes to this line
rm -f ./${name}.cpio; done; done; done
 
Old 08-16-2006, 08:56 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
ok now the error comes to this line
Sorry, not enough information.
Please post actual debug output.
 
Old 08-16-2006, 09:02 PM   #9
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
syntax error near unexpected token 'done'
rm -f ./${name}.cpio; done; done; done

ah, well, if this is causing you problems, dont reply back. I will reinstall, was just doing it to learn something.
 
Old 08-17-2006, 06:06 AM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
ah, well, if this is causing you problems, dont reply back.
If something causes problems then one *should* post.


I will reinstall, was just doing it to learn something.
It's so fsckin simple. I asked you twice to post back debug output which you didn't on both occasions. If you can't or won't cooperate by posting debug output then tell me how I am supposed to determine what goes wrong on your box? Cuz my ESP is at an alltime low.
 
Old 08-17-2006, 07:24 AM   #11
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
ok, sorry for the short posts.
here goes

I have removed the first line cd $TEMP, dont think that would cause a problem.
cat trial.sh
Quote:
rpm -qa --dump|grep /usr/bin|awk '{print $1}'|while read bin; do
rpm -q --whatprovides "$bin" >/dev/null || echo "\"${bin}\""; done|sort|uniq|while read name; do
find /mnt/Fedora/RPMS -type f -name ${name}\*.rpm|head -1|while read rpm; do
rpm2cpio $rpm > ./${name}.cpio && \
cat ./${name}.cpio|cpio -ivd --no-absolute-filenames "./usr/bin/*"
rm -f ./${name}.cpio; done; done; done

sh -x trial.sh 2>&1 | trial.log
Quote:
-bash: trial.log : command not found
sh trial.sh 2>&1
Quote:
trial.sh:line 6: syntax error near unexpected token 'done'
trial.sh:line 6: 'rm -f ./${name}.cpio; done; done; done'
this is where I am
Quote:
chmod 777 /root/tmp
pwd
/root/tmp
 
Old 08-17-2006, 08:32 AM   #12
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
sh -x trial.sh 2>&1 | trial.log
Should have read "sh -x trial.sh 2>&1 | tee trial.log"


trial.sh:line 6: 'rm -f ./${name}.cpio; done; done; done'
One "done" too much. The script should look like this:

Code:
rpm -qa --dump|grep /usr/bin|awk '{print $1}'|while read bin; do 
rpm -q --whatprovides "$bin" >/dev/null; done|sort|uniq|while read name; do
find /mnt/Fedora/RPMS -type f -name ${name}\*.rpm|while read rpm; do
rpm2cpio $rpm > ./${name}.cpio && \
cat ./${name}.cpio|cpio -ivd --no-absolute-filenames "./usr/bin/*"
rm -f ./${name}.cpio; done; done
Definately should work now. Thanks for debugging.
 
Old 08-17-2006, 08:51 AM   #13
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
after removing the extra done
I still get the error
Quote:
trial.sh:line 6: syntax error near unexpected token 'done'
trial.sh:line 6: 'rm -f ./${name}.cpio; done; done'
I knew there was a extra done and had removed it earlier, but it made no difference so I let it remained in the script.
 
Old 08-17-2006, 12:11 PM   #14
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
ok I figured out why the script doesnt workout.
uniq and find both commands are in the /usr/bin directory, so this wont work.
although uniq can be done by a sed command
sed '$!N; /^\(.*\)\n\1$/!P; D'

next, you would need rpm2cpio which again is in /usr/bin/

I will see if I can do this some other way.
 
Old 08-17-2006, 01:06 PM   #15
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
now this is totally awesome, I finally got the script to work and now my dead system is backup with everything.
cool unspawn, your the best!
didnt know rpm could do this!

anyway, what I did was got linux rescue mode and copy the files find, rpm2cpio,uniqetc. to my deleted /usr/bin. rebooted, ran unspawn's script and I got back my /usr/bin, totally awesome.

one thing though, I ran the second script it gives all command not found errors, I guess its missing the work "chmod" in it.
 
  


Reply



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
what is difference between /usr/bin/7za /usr/bin/7z fakie_flip Linux - Software 9 08-14-2006 09:22 PM
Ubuntu 5.10 -> 6.06: diversion of /usr/bin/ldd to /usr/bin/ldd.amd64 by ia32-libs HellSpawn Linux - Software 2 06-04-2006 09:18 PM
path in services wrong for clamav updated frm 0.75 to 0.80 usr/bin vs usr/local/bin Emmanuel_uk Linux - Newbie 3 04-22-2005 01:02 AM
problem with NS_NewNativeLocalFile on enterprise Linux3.0 montylee Linux - Software 0 03-16-2005 08:05 AM
/usr/bin/X11/ and /usr/X11R6/bin/ the same? linuxtesting2 Linux - Newbie 2 11-16-2004 10:57 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 01:54 PM.

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