Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

trying to write a script to loop through a port info file

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-07-2008   -   Original Discussion by rcon1
rcon1 rcon1 is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 30 June 2008, 9:40 AM EDT
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
trying to write a script to loop through a port info file

Below is part of a script i have written to loop through part of a port info file. How do i continue the script to get info for OS Device Name, manufacturer and then put information into an array?

HBA Port WWN: 10000000c9420b4b
OS Device Name: /dev/cfg/c10
Manufacturer: Emulex
Model: LP10000DC-S
Firmware Version: 1.92a1
FCode/BIOS Version: none
Type: N-port
State: online
Supported Speeds: 1Gb 2Gb
Current Speed: 2Gb
Node WWN: 20000000c9420b4b

#!/bin/ksh

PORT_INFOFILE=/tmp/aa

if [ -f $PORT_INFOFILE ]; then
rm -f $PORT_INFOFILE
touch $PORT_INFOFILE
fi

# read port info

fcinfo hba-port >> $PORT_INFOFILE 2>&1

cat $PORT_INFOFILE | while read line; do

x=`echo $line | grep "HBA Port"`
if [ -n $x ]; then
NEW_PORT="TRUE"
else
NEW_PORT="FALSE"
fi
Sponsored Links
    #2  
Old Unix and Linux 01-07-2008   -   Original Discussion by rcon1
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
 
Join Date: Dec 2007
Last Activity: 28 July 2016, 2:18 PM EDT
Posts: 1,152
Thanks: 4
Thanked 92 Times in 89 Posts
Here is simple framework you can work with.


Code:
#!/bin/ksh

cat data | while read one two
do
   case $one in 
      "HBA" ) echo "HBA is $two"
         ;;
      * ) echo "one=[$one] two=[$two]"
         ;;
   esac
done

$ ./parse.file
HBA is Port WWN: 10000000c9420b4b
one=[OS] two=[Device Name: /dev/cfg/c10]
one=[Manufacturer:] two=[Emulex]
one=[Model:] two=[LP10000DC-S]
one=[Firmware] two=[Version: 1.92a1]
one=[FCode/BIOS] two=[Version: none]
one=[Type:] two=[N-port]
one=[State:] two=[online]
one=[Supported] two=[Speeds: 1Gb 2Gb]
one=[Current] two=[Speed: 2Gb]
one=[Node] two=[WWN: 20000000c9420b4b]
Sponsored Links
    #3  
Old Unix and Linux 01-07-2008   -   Original Discussion by rcon1
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
 
Join Date: Dec 2007
Last Activity: 28 July 2016, 2:18 PM EDT
Posts: 1,152
Thanks: 4
Thanked 92 Times in 89 Posts
actually. this is even better and gives you an array like you wanted.


Code:
#!/bin/ksh

cat data | while read line
do
   set -A array $line
   echo "array[0]=${array[0]}"
   echo "array[1]=${array[1]}"
   # ... you get the point
   echo
done

    #4  
Old Unix and Linux 01-07-2008   -   Original Discussion by rcon1
porter porter is offline Forum Advisor  
Registered User
 
Join Date: Jan 2007
Last Activity: 8 January 2008, 6:50 PM EST
Posts: 2,965
Thanks: 0
Thanked 5 Times in 5 Posts
Quote:
Originally Posted by frank_rizzo View Post
actually. this is even better
or this..


Code:
while read line
do
    ...
done <data

Sponsored Links
    #5  
Old Unix and Linux 01-07-2008   -   Original Discussion by rcon1
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
 
Join Date: Dec 2007
Last Activity: 28 July 2016, 2:18 PM EDT
Posts: 1,152
Thanks: 4
Thanked 92 Times in 89 Posts
Quote:
Originally Posted by porter View Post
or this..


Code:
while read line
do
    ...
done <data

nice...I like it!
Sponsored Links
    #6  
Old Unix and Linux 01-09-2008   -   Original Discussion by rcon1
rcon1 rcon1 is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 30 June 2008, 9:40 AM EDT
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
cheers! thanks for the comments
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to loop line in a file and add info or do echo sabercats Shell Programming and Scripting 8 05-03-2012 05:15 PM
Unable to write to a file within a loop janardhanamk UNIX for Dummies Questions & Answers 1 11-15-2010 07:54 AM
Push records to array during implicit loop and write to file jospan Shell Programming and Scripting 0 01-12-2010 09:06 AM
How to pull info under headers in file(awk,grep,while loop) kieranfoley Shell Programming and Scripting 2 01-04-2010 07:26 PM
Loop through file and write out lines to file(s) Jtrinh Shell Programming and Scripting 7 07-05-2005 04:06 AM



All times are GMT -4. The time now is 07:51 PM.