cancel
Showing results for 
Search instead for 
Did you mean: 

script help

SOLVED
Go to solution
Nobody's Hero
Valued Contributor

script help

yea, im not a very good scripter, although I try very hard before I post for help, really.

I have a file that looks like this:
running "ls -l /etc/rc2.d/" on 172.xx.xxx.xxx:
-------------------------------------------------------------------------------
total 178
lrwxrwxrwx 1 root other 20 Jul 23 2007 K00.umask.sh -> /etc/init.d/umask.sh
lrwxrwxrwx 1 root other 26 Oct 2 2006 K02patchlinkagent -> /etc/init.d/patchlinkagent
-rwxr--r-- 1 root sys 344 Mar 20 2000 K06mipagent
-rwxr--r-- 1 root sys 861 Jan 5 2000 K07dmi
-rwxr--r-- 1 root sys 404 Jan 5 2000 K07snmpdx
-rwxr--r-- 6 root sys 621 Sep 1 21:53 K21dhcp
-rwxr--r-- 1 root sys 3080 Jan 5 2000 K28nfs.server
-rwxr-xr-x 1 root other 8543 Feb 25 2003 K50Tivoli_lcf1
lrwxrwxrwx 1 root other 20 Jul 23 2007 S00.umask.sh -> /etc/init.d/umask.sh
-rwxr--r-- 1 root sys 1881 Jan 5 2000 S01MOUNTFSYS
-rwxr--r-- 1 root sys 789 Apr 28 2004 S01VXFSLDLIC
-rwxr--r-- 1 root sys 2266 Dec 17 2002 S05RMTMPFILES
-rwxr--r-- 1 root sys 611 Jan 5 2000 S20sysetup
-rwxr--r-- 5 root sys 1517 Oct 28 21:49 S47asppp
-rwxr--r-- 5 root sys 1706 Oct 28 21:47 S47pppd
-r-xr-xr-x 1 root other 5813 Jan 10 2007 S68SEOS
-rwxr--r-- 1 root sys 12246 Dec 13 2004 S69inet
-rwxr--r-- 5 root sys 420 Oct 28 21:49 S71ldap.client
-rwxr--r-- 1 root sys 7278 Dec 19 2004 S72inetsvc
-rwxr--r-- 1 root sys 1144 May 19 2004 S73cachefs.daemon
-rwxr--r-- 1 root sys 911 Jan 5 2000 S74syslog
-rwxr--r-- 1 root sys 504 Jan 5 2000 S75cron
lrwxrwxrwx 1 root other 22 Jul 23 2007 S90tt_s02a111 -> /etc/init.d/tt_s02a111
-r-xr-xr-x 1 root sys 2333 Dec 5 2002 S94vxnm-vxnetd
-r-xr-xr-x 1 root sys 2309 Jun 26 2007 S95vxvm-recover
-r-x------ 1 root sys 2764 Dec 5 2002 S96vradmind
-r-x------ 1 root sys 2821 Dec 5 2002 S96vxrsyncd
-rwxr--r-- 1 root sys 493 Aug 7 2000 S98efcode
-r-xr-xr-x 1 root other 3692 Jan 10 2007 S99SEOS
lrwxrwxrwx 1 root other 18 Aug 1 2007 S99eccmad -> /etc/init.d/eccmad
-r-x--x--- 1 root other 6192 Mar 5 2005 _S68SEOS
-rwxr--r-- 2 root sys 715 Jan 20 2008 k16apache

and it repeats itself over and over for every IP we have.

how can I cut just the IP address and just the S9 programs that list under that IP?
I tried this but the IP's are all on top and the S9's are on the bottom.

cat rc2* | grep running |awk -F" " '{ print $6 }' && cat rc2* | awk -F" " '{ print $9 }' |grep S9 > fileout
UNIX IS GOOD
3 REPLIES
Eric SAUBIGNAC
Honored Contributor
Solution

Re: script help

Bonsoir,

Don't know exactly how you want to present output. Here is what I can imagine in a first approach :

sed 's=^running "ls -l /etc/rc2.d/" on =FLAG_IP =' YourFile | sed 's=^.* S9=FLAG_S9 S9=' | grep "^FLAG_.. " | sed 's=^FLAG_IP =Found on node =' | sed 's=FLAG_S9 =- ='

From your example, copy/pasted in the file YourFile, it gives :

-----------------------------------------
Found on node 172.xx.xxx.xxx:
- S90tt_s02a111 -> /etc/init.d/tt_s02a111
- S94vxnm-vxnetd
- S95vxvm-recover
- S96vradmind
- S96vxrsyncd
- S98efcode
- S99SEOS
- S99eccmad -> /etc/init.d/eccmad
-----------------------------------------

Eric
TTr
Honored Contributor

Re: script help

A simple

grep -e running -e S9 filename

should be sufficient. The grep command with multiple search strings keeps its matching findings in the order that it finds them in the file.
Heironimus
Honored Contributor

Re: script help

No need for quite so many commands, you should be able to do it in one... something like one of these should do what you need.


sed -ne 's/^running .* on \(.*\):/\1/p; s/.* \(S9[^ ]*\).*/\1/p'


awk '/^running / { print $6; } / S9/ { print $9; }'