Find strings from history

I am trying to find commands for 'history' containing 'gcc.4.1.1.tar'.

for i in `cut -d: -f6 /etc/passwd`
do
     if [ -f "$i/.sh_history" ]
     then
          echo "$i/.sh_history"
          grep "^gcc.4.1.1.tar" "$i/.sh_history"
     fi
done


but, it doesn't return what I need.  How to do?
JohnLucaniaAsked:
Who is Participating?
 
enyamadaCommented:

You must execute the script as root, otherwise we will get the permission errors that you are experiencing.

0
 
enyamadaCommented:
Hi,

The "^" in the regular expression means beginning-of-the-line. As "gcc.4.1.1.tar" is not
something usually typed at the beginning of a command, maybe there it is the mistake.

Try then:

for i in `cut -d: -f6 /etc/passwd`
do
     if [ -f "$i/.sh_history" ]
     then
          echo "$i/.sh_history"
          grep "gcc.4.1.1.tar" "$i/.sh_history"
     fi
done


Rgds
0
 
JohnLucaniaAuthor Commented:
It returns:
//.sh_history
grep: 0652-033 Cannot open //.sh_history.
//.sh_history
grep: 0652-033 Cannot open //.sh_history.
//.sh_history
grep: 0652-033 Cannot open //.sh_history.
/home/oracle/.sh_history
grep: 0652-033 Cannot open /home/oracle/.sh_history.
/home/d_prod/.sh_history
          grep "gcc.4.1.1.tar" "$i/.sh_history"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.