Need complex script, anyone up for a challenge?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need complex script, anyone up for a challenge?
# 1  
Old 12-01-2008
Need complex script, anyone up for a challenge?

Default shell is /usr/bin/zsh
Script will be running #!/bin/bash

Need to pull information from database while using other scripts already made (not by me).
Ok, so i need a script pulling certain information about a customer's router interfaces.
I am using a ROUTER-DNS-NAME as variable $1
I already figured out how to obtain an output similar to the following from the SCRIPT1 that is already made:

.34
.35

After i receive those numbers, i have to run a separate script using those numbers in the end of the command, here is an example output result needed:
SCRIPT2 $1 ANYTHING.34

Having a little trouble figuring out how to connect those together within one script file.

In order for me to get first numbers i had to do a pretty long set of commands:
SCRIPT2 $1 ANYTHING | grep "`SCRIPT1 $1 | grep -i $1 | grep SOMETHING1 | grep -v NULL | cut -d"(" -f2 | cut -d"." -f1`" | cut -d"r" -f2 | cut -d" " -f1


I have SCRIPT1 interface names within SCRIPT2 to get their numbers (.34, .35 - i need that period!), then use SCRIPT2 back with those numbers.
If i use: SCRIPT2 $1 ANYTHING - this will pull all the interface info.

here is the similar output of SCRIPT1:
NODE IP(DOMAIN) STATE
----------------------------------------------- ------------------ ------
ROUTER-DNS-NAME (INTERFACE0/0) NULL(1) SOMETHING4
ROUTER-DNS-NAME (INTERFACE0/0/0:1) NULL(1) SOMETHING1
ROUTER-DNS-NAME (INTERFACE0/0/0:1.100) IPADDESS(1) SOMETHING1

Much of my script will have to contain the text formatting as per customer table punctuation. None of the names, have any specific lenght, so had to use fields.

Please advise what else i need to explain in order to get some help here.
Thank you.
# 2  
Old 12-05-2008
Hrm, seems you need the following tip:
Code:
cat <<EOF | while read X; do echo SCRIPT2 $X ANYTHING
.34
.35
EOF

As far as your complex SCRIPT2 processing, you could simplify it with something like this:
Code:
SCRIPT1 $1 | awk '/'"$1"'/ && /SOMETHING/ && !/NULL/' | sed -e 's/.*(//; s/\..*$//;' |
while read X; do 
  SCRIPT2 .$X
done

But I'm not sure if I correctly understand the problem.
# 3  
Old 12-07-2008
output edit of Script using sub-scripts

Hello everyone,

echo $SHELL
/usr/local/bin/zsh

I will make myself as clear as i can possibly be.
There are two scripts i am using at work, SCRIPT1 and SCRIPT2 (i didn't make these).
The information is output to standard out on both with an inquiry about ROUTER-DNS-NAME-NUMBER (1st variable).
Some of information is unnecessary and just takes up space on output, making everything look confusing.
SCRIPT1 pulling static database, SCRIPT2 pulling real-time statistics from ROUTER-DNS-NAME-NUMBER.
I am looking into combining both scripts with a different script in order to perform one major activity needed for my everyday work.
I will be using this script 100+ times a day, so a temporary solution will not work.
I currently have two scripts running almost providing me desired effect, but it could be done better, i just do not know how. Current name of the scripts is as per below 'wa' and 'wi'. The script that i am asking for supposed to use only one variable, which is ROUTER-DNS-NAME-NUMBER ($1) and do the following:

1. Execute SCRIPT1 and determine necessary interface to pull information from. from the examples bellow it is shown that interface of interest could be any interface with a sub-interface (interest: "serial0" of sub-interface: "serial0.101"); it also could be an interface with an IPADDRESS; and/or a interface with word Serial or Ethernet. Sub-interfaces should be omitted as SCRIPT2 executed on them does not provide any valuable information.
2. Execute SCRIPT2 for those interfaces only to pull valuable information.

So far i think what i need is to have script follow these steps:
A. run SCRIPT1 ROUTER-DNS-NAME-NUMBER and filter out only to show necessary interfaces, assign each a VARIABLE1
B. run SCRIPT2 ROUTER-DNS-NAME-NUMBER ifDescr and filter out only VARIABLE1, assign interface INTEGER (located right after ifDescr) as VARIABLE2
C. then output the following for every VARIABLE1:
SCRIPT2 $1 ifDescr.$VARIABLE2
SCRIPT2 $1 ifAlias.$VARIABLE2
SCRIPT2 $1 ifPhysAddress.$VARIABLE2
SCRIPT2 $1 ifMtu.$VARIABLE2
SCRIPT2 $1 ifSpeed.$VARIABLE2
SCRIPT2 $1 ifAdminStatus.$VARIABLE2
SCRIPT2 $1 ifOperStatus.$VARIABLE2
SCRIPT2 $1 ifInOctets.$VARIABLE2
SCRIPT2 $1 ifInErrors.$VARIABLE2
SCRIPT2 $1 ifOutOctets.$VARIABLE2
SCRIPT2 $1 ifOutErrors.$VARIABLE2
SCRIPT2 $1 ifType.$VARIABLE2
SCRIPT2 $1 ifName.$VARIABLE2

So if anyone can help, i would appreciate it!
Obviously, there will be needed a lot of text filtering to get only desired output.
Moving the examples to notepad will allign it properly (you can also use font like "Courier New" - just easier to read.
Here are the suplimental info:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#example1:
:~> SCRIPT1 ROUTER-DNS-NAME-NUMBER
NODE IP(DOMAIN) STATE
----------------------------------------------- ------------------ ------
ROUTER-DNS-NAME-NUMBER(FastEthernet0/0) IPADDRESS(11) Unmgd
ROUTER-DNS-NAME-NUMBER(Loopback0) IPADDRESS(11) Mgd
ROUTER-DNS-NAME-NUMBER(FastEthernet0/1) NULL(11) Mgd
ROUTER-DNS-NAME-NUMBER(Null0) NULL(11) Unmgd
ROUTER-DNS-NAME-NUMBER(E1 0/1/0) NULL(11) Mgd
ROUTER-DNS-NAME-NUMBER(E1 0/1/1) NULL(11) Mgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:1) NULL(11) Mgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/1:1) NULL(11) Mgd
ROUTER-DNS-NAME-NUMBER(Multilink1) IPADDRESS(11) Mgd


#example2:
:~> SCRIPT1 ROUTER-DNS-NAME-NUMBER
NODE IP(DOMAIN) STATE
----------------------------------------------- ------------------ ------
ROUTER-DNS-NAME-NUMBER(FastEthernet0) IPADDRESS(3) Mgd
ROUTER-DNS-NAME-NUMBER(Serial0) NULL(3) Mgd
ROUTER-DNS-NAME-NUMBER(Null0) NULL(3) Unmgd
ROUTER-DNS-NAME-NUMBER(Loopback0) IPADDRESS(3) Mgd
ROUTER-DNS-NAME-NUMBER(Serial0.101) IPADDRESS(3) Mgd
ROUTER-DNS-NAME-NUMBER(Serial0.101) IPADDRESS(3) Mgd


#example3:
:~> SCRIPT1 ROUTER-DNS-NAME-NUMBER
NODE IP(DOMAIN) STATE
----------------------------------------------- ------------------ ------
ROUTER-DNS-NAME-NUMBER(GigabitEthernet0/0) IPADDRESS(7) Mgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:0) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20019) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/20) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20020) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/21) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20021) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/22) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20022) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/23) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20023) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/24) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:1) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20024) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/25) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20025) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/26) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20026) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/27) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20027) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/28) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20028) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/29) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:2) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20029) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/30) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20030) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/31) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20031) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/32) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20032) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/33) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20033) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/34) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:3) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20034) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/35) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20035) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/36) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20036) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/37) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20037) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/38) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20038) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/39) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:4) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20039) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/40) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20040) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/41) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20041) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/42) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20042) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/43) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20043) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/44) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:5) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20044) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/45) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20045) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:6) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:7) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:8) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:9) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(GigabitEthernet0/1) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:10) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:11) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:12) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:13) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:14) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:15) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:16) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:17) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:18) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:19) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:20) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:21) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:22) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:23) NULL(7) Mgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:23-Signaling) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:0-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:1-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:2-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:3-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:4-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Null0) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:5-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:6-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:7-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:8-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:9-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:10-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:11-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:12-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:13-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:14-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(T1 0/0/0) NULL(7) Mgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:15-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:16-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:17-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:18-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:19-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:20-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:21-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/1/0:22-Bearer Channel) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(DS0 Group 0/1/0:23) NULL(7) Mgd
ROUTER-DNS-NAME-NUMBER(Tunnel1) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(T1 0/0/1) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/0/0:0.100) IPADDRESS(7) Mgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 1) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 9) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/1) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20001) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/2) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20002) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/3) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20003) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/4) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(T1 0/1/0) NULL(7) Mgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20004) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/5) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20005) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/6) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20006) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/7) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20007) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/8) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20008) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/9) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(T1 0/1/1) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20009) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/10) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20010) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/11) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20011) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/12) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20012) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/13) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20013) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/14) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Serial0/0/0:0) NULL(7) Mgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20014) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/15) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20015) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/16) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20016) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/17) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20017) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/18) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(Voice Encapsulation (POTS) Peer: 20018) NULL(7) Unmgd
ROUTER-DNS-NAME-NUMBER(EFXS 50/0/19) NULL(7) Unmgd

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

:~> cat bin/wa
#!/bin/bash
SCRIPT2 $1 ipAdEntIfIndex
SCRIPT2 $1 ifDescr | egrep -v "Bearer Channel|STRING: EFXS|STRING: Voice Encapsulation"
SCRIPT2 $1 ifAdminStatus
SCRIPT2 $1 ifOperStatus
SCRIPT2 $1 ifInOctets | grep -v "Counter32: 0"
SCRIPT2 $1 ifInErrors | grep -v "Counter32: 0"
SCRIPT2 $1 ifAlias


#example1 output:
:~> wa ROUTER-DNS-NAME-NUMBER
ipAdEntIfIndex.IPADDRESS = INTEGER: 10
ipAdEntIfIndex.IPADDRESS = INTEGER: 1
ipAdEntIfIndex.IPADDRESS = INTEGER: 9
ifDescr.1 = STRING: "FastEthernet0/0"
ifDescr.2 = STRING: "FastEthernet0/1"
ifDescr.4 = STRING: "Null0"
ifDescr.5 = STRING: "E1 0/1/0"
ifDescr.6 = STRING: "E1 0/1/1"
ifDescr.7 = STRING: "Serial0/1/0:1"
ifDescr.8 = STRING: "Serial0/1/1:1"
ifDescr.9 = STRING: "Multilink1"
ifDescr.10 = STRING: "Loopback0"
ifAdminStatus.1 = INTEGER: up(1)
ifAdminStatus.4 = INTEGER: up(1)
ifAdminStatus.5 = INTEGER: up(1)
ifAdminStatus.6 = INTEGER: up(1)
ifAdminStatus.7 = INTEGER: up(1)
ifAdminStatus.8 = INTEGER: up(1)
ifAdminStatus.9 = INTEGER: up(1)
ifAdminStatus.10 = INTEGER: up(1)
ifOperStatus.1 = INTEGER: up(1)
ifOperStatus.2 = INTEGER: down(2)
ifOperStatus.4 = INTEGER: up(1)
ifOperStatus.5 = INTEGER: up(1)
ifOperStatus.6 = INTEGER: up(1)
ifOperStatus.7 = INTEGER: up(1)
ifOperStatus.8 = INTEGER: up(1)
ifOperStatus.9 = INTEGER: up(1)
ifOperStatus.10 = INTEGER: up(1)
ifInOctets.1 = Counter32: 2034694446
ifInOctets.7 = Counter32: 701966032
ifInOctets.8 = Counter32: 752641178
ifInOctets.9 = Counter32: 1311327751
ifInErrors.1 = Counter32: 6
ifInErrors.7 = Counter32: 24698
ifInErrors.8 = Counter32: 2012
ifAlias.1 = STRING: "DESC"
ifAlias.2 = ""
ifAlias.4 = ""
ifAlias.5 = ""
ifAlias.6 = ""
ifAlias.7 = STRING: "DESC"
ifAlias.8 = STRING: "DESC"
ifAlias.9 = STRING: "DESC"
ifAlias.10 = STRING: "DESC"


#example2 output:
:~> wa ROUTER-DNS-NAME-NUMBER
IP-MIB::ipAdEntIfIndex.IPADDRESS = INTEGER: 1
IP-MIB::ipAdEntIfIndex.IPADDRESS = INTEGER: 5
IP-MIB::ipAdEntIfIndex.IPADDRESS = INTEGER: 6
IP-MIB::ipAdEntIfIndex.IPADDRESS = INTEGER: 6
IF-MIB::ifDescr.1 = STRING: FastEthernet0
IF-MIB::ifDescr.2 = STRING: Serial0
IF-MIB::ifDescr.3 = STRING: Null0
IF-MIB::ifDescr.5 = STRING: Loopback0
IF-MIB::ifDescr.6 = STRING: Serial0.101
IF-MIB::ifAdminStatus.1 = INTEGER: up(1)
IF-MIB::ifAdminStatus.2 = INTEGER: up(1)
IF-MIB::ifAdminStatus.3 = INTEGER: up(1)
IF-MIB::ifAdminStatus.5 = INTEGER: up(1)
IF-MIB::ifAdminStatus.6 = INTEGER: up(1)
IF-MIB::ifOperStatus.1 = INTEGER: up(1)
IF-MIB::ifOperStatus.2 = INTEGER: up(1)
IF-MIB::ifOperStatus.3 = INTEGER: up(1)
IF-MIB::ifOperStatus.5 = INTEGER: up(1)
IF-MIB::ifOperStatus.6 = INTEGER: up(1)
IF-MIB::ifInOctets.1 = Counter32: 95527551
IF-MIB::ifInOctets.2 = Counter32: 205831765
IF-MIB::ifInOctets.6 = Counter32: 204062927
IF-MIB::ifInErrors.2 = Counter32: 2
IF-MIB::ifAlias.1 = STRING:
IF-MIB::ifAlias.2 = STRING: DESC
IF-MIB::ifAlias.3 = STRING:
IF-MIB::ifAlias.5 = STRING:
IF-MIB::ifAlias.6 = STRING: DESC

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

:~> cat bin/wi
#!/bin/bash
SCRIPT2 $1 ifDescr$2
SCRIPT2 $1 ifAlias$2
SCRIPT2 $1 ifPhysAddress$2
SCRIPT2 $1 ifMtu$2
SCRIPT2 $1 ifSpeed$2
SCRIPT2 $1 ifAdminStatus$2
SCRIPT2 $1 ifOperStatus$2
SCRIPT2 $1 ifInOctets$2
SCRIPT2 $1 ifInErrors$2
SCRIPT2 $1 ifOutOctets$2
SCRIPT2 $1 ifOutErrors$2
SCRIPT2 $1 ifType$2
SCRIPT2 $1 ifName$2


#example1 output:
:~> wi ROUTER-DNS-NAME-NUMBER .1
ifDescr.1 = STRING: "FastEthernet0/0"
ifAlias.1 = STRING: "DESC"
ifPhysAddress.1 = Hex-STRING: 00 00 00 00 00 00
ifMtu.1 = INTEGER: 1500
ifSpeed.1 = Gauge32: 100000000
ifAdminStatus.1 = INTEGER: up(1)
ifOperStatus.1 = INTEGER: up(1)
ifInOctets.1 = Counter32: 2034644585
ifInErrors.1 = Counter32: 6
ifOutOctets.1 = Counter32: 1459047637
ifOutErrors.1 = Counter32: 0
ifType.1 = INTEGER: ethernet-csmacd(6)
ifName.1 = STRING: "Fa0/0"


#example2 output:
:~> wi ROUTER-DNS-NAME-NUMBER .2
IF-MIB::ifDescr.2 = STRING: Serial0
IF-MIB::ifAlias.2 = STRING: DESC
IF-MIB::ifPhysAddress.2 = STRING:
IF-MIB::ifMtu.2 = INTEGER: 1500
IF-MIB::ifSpeed.2 = Gauge32: 64000
IF-MIB::ifAdminStatus.2 = INTEGER: up(1)
IF-MIB::ifOperStatus.2 = INTEGER: up(1)
IF-MIB::ifInOctets.2 = Counter32: 205837199
IF-MIB::ifInErrors.2 = Counter32: 2
IF-MIB::ifOutOctets.2 = Counter32: 120597226
IF-MIB::ifOutErrors.2 = Counter32: 0
IF-MIB::ifType.2 = INTEGER: frameRelay(32)
IF-MIB::ifName.2 = STRING: Se0

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 4  
Old 12-07-2008
Quote:
Originally Posted by otheus
Hrm, seems you need the following tip:
Code:
cat <<EOF | while read X; do echo SCRIPT2 $X ANYTHING
.34
.35
EOF

As far as your complex SCRIPT2 processing, you could simplify it with something like this:
Code:
SCRIPT1 $1 | awk '/'"$1"'/ && /SOMETHING/ && !/NULL/' | sed -e 's/.*(//; s/\..*$//;' |
while read X; do 
  SCRIPT2 .$X
done

But I'm not sure if I correctly understand the problem.


this did not work, i guess i should have explained better, i have created different thread due to lengthy explanation and statement of the issue.

https://www.unix.com/shell-programmin...b-scripts.html
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Challenge with sh script using environment variables to check for file.

Hi All Thanks for reviewing my question. I have a sh script where I used an environmental variable for the directory for the file I need to check to ensure before executing a process. I have confirmed the permissions and I can find the file if I use a hard coding of the directory. This is a... (5 Replies)
Discussion started by: rstojkovic68
5 Replies

2. Shell Programming and Scripting

Help with Complex Bash Script

I have an FTP server with thousands of Invoices. All Invoices are in a folder called /volume1/MBSInvoices/ Monthly invoices are added to that folder every month. Here is a sample filename of the Invoices: invoice_1_20170101_10010052_10020052_10030052_JOHNDOE.pdf the Account ID is the... (6 Replies)
Discussion started by: badr777
6 Replies

3. Shell Programming and Scripting

Complex transpose awk script

Hello to all in forum, Maybe an awk expert could help me with this complex task for me. I have the input shown below and I would like to get the output as follow: - I would like the output separated by commas. - The header is fixed and will be the same always. - For the lines containing... (22 Replies)
Discussion started by: Ophiuchus
22 Replies

4. Shell Programming and Scripting

Shell script menu for end user - difficult challenge 2

Hello, I need to make shell script menu for my end users. There is like 100 scripts in system, and they need to run that scripts true one main script with user friendly menu. Example, when user will run main menu script, it will get something like this on his screen:... (1 Reply)
Discussion started by: waso
1 Replies

5. Shell Programming and Scripting

awk script (complex)

picked this up from another thread. echo 1st_file.csv; nawk -F, 'NR==FNR{a++;next} a{b++} END{for(i in b){if(b-1&&a!=b){print i";\t\t"b}else{print "NEW:"i";\t\t"b} } }' OFS=, 1st_file.csv *.csv | sort -r i need to use the above but with a slight modification.. 1.compare against 3 month... (25 Replies)
Discussion started by: slashbash
25 Replies

6. Shell Programming and Scripting

Shell script menu for end user - difficult challenge

Hello, I need to make shell script menu for my end users. There is like 100 scripts in system, and they need to run that scripts true one main script with user friendly menu. Example, when user will run main menu script, it will get something like this on his screen:... (3 Replies)
Discussion started by: waso
3 Replies

7. Shell Programming and Scripting

Complex Script

hey... i had a big problem with my professor i have 3 simple archives in.txt -> had all timestamps of users logon (100lines) ex. 111111 222222 333333 out.txt -> had all timestamps of users logof (100lines) ex. 111113 222225 333332 commands.txt... (9 Replies)
Discussion started by: beandj
9 Replies

8. Shell Programming and Scripting

Complex coloring in script

My script prints lines in which the entire line may be colored, and portions may also be colored. e.g. Consider this to be one line: $red some text in red $yellow abcd $end_yellow red text 1234 $blue some text $end_blue more red text $end_red So using sed, I may based on condition 1,... (5 Replies)
Discussion started by: sentinel
5 Replies

9. Shell Programming and Scripting

need shell script for this challenge problem

two tabulate files (A, B), each contents thousands and thousands lines with ids. first find out contents with common ids in both A, B and print out into a file; second find out contents with ids which only exist in file A and print out into a file. (4 Replies)
Discussion started by: ssshen
4 Replies

10. Shell Programming and Scripting

complex find in script

How to I put my find command string into a script. It is currently to long to be entered manually at command line. for FNAME in `find /unixsxxx/interface/x.x/xxxxxx -type f \( -name '*.KSH' -o -name '*.sh' -o -name '*.sql' -o -name '*.ksh' \) -exec grep -il xxx.xxx.xxx.xxx {} \;`; do C=`grep -c... (5 Replies)
Discussion started by: TimHortons
5 Replies
Login or Register to Ask a Question