Languages and Scripting

how grep rm command for sh_history of multiple user?

 
kpatel786
Frequent Advisor

how grep rm command for sh_history of multiple user?

On one of our hp server we have 200 users.
I want to find who ran rm command from the repective home directories sh_history file of the users.
I tried grep with for loop but give all junk character.
Kindly assist at the earliest.
5 REPLIES 5
Oviwan
Honored Contributor

Re: how grep rm command for sh_history of multiple user?

hey

an easy script would be this:

cd /home
while user in $(ls) ; do
echo $user
grep rm $user/.sh_history
done

or maybe you can poste you script...

regards
Pete Randall
Outstanding Contributor

Re: how grep rm command for sh_history of multiple user?

grep -l "rm" /home/*/.sh_history


Pete

Pete
kpatel786
Frequent Advisor

Re: how grep rm command for sh_history of multiple user?

Thank you guys for you assistance
Dennis Handly
Acclaimed Contributor

Re: how grep rm command for sh_history of multiple user?

>I tried grep with for loop but give all junk character.

.sh_history has binary characters. In some cases, grepping them locks up my hpterm.
You can pipe the results to vis(1) to prevent this. Taking Pete's example:
grep -n "rm" /home/*/.sh_history | vis
kpatel786
Frequent Advisor

Re: how grep rm command for sh_history of multiple user?

thanks.