Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 692
  • Last Modified:

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?
0
JohnLucania
Asked:
JohnLucania
  • 2
1 Solution
 
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
 
enyamadaCommented:

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

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now