awk multiline with 1 or more variables (question)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk multiline with 1 or more variables (question)
# 1  
Old 09-01-2010
awk multiline with 1 or more variables (question)

am trying to grab the fields marked in red for monitoring purposes. each vfiler can have anywhere from 0-50 Path(s).

in order to get here i run the following
Code:
for filer in `cat filers.list` ; do ssh $filer  vfiler status | awk '{print $1}' ; done

this returns
Code:
vfiler0
vfilert
vfiler2

based on this i would now ssh to each vfiler and do a vfiler status -r to find out what Paths are assigned to this vfiler, and then run ssh vfiler df -h for each Path (hoping i can do this all through awk)
so now the question is , the output is on multiple lines, how would i grab the blue (hostname) and red (Path) only ?
Code:
vfiler0                         running
   ipspace: default-ipspace
   IP address: 192.168.56.104 [ns0]
   IP address: 192.168.56.201 [ns1]
   Path: / [/etc]
   UUID: 00000000-0000-0000-0000-000000000000

vfilert                          running
   ipspace: default-ipspace
   IP address: 192.168.56.202 [ns0]
   Path: /vol/vfiler_vol [/etc]
   Path: /vol/virt_vol
   UUID: 87ae189e-b6c6-11df-ac98-00505614cd84

vfiler2                          running
   ipspace: default-ipspace
   IP address: 192.168.56.205 [ns1]
   Path: /vol/vfiler2_vol0 [/etc]
   UUID: f43ab782-b77b-11df-94a6-00505614cd84


Last edited by Scott; 09-01-2010 at 06:43 PM.. Reason: Added code tags
# 2  
Old 09-01-2010
something along these lines:
Code:
#!/bin/ksh
while read filer
do
  ssh $filer vfiler status | awk '{print $1}')
  ssh $filer vfiler status -r | awk '/^Path/{print substr($0, 1, index($0," [")-1)}'
done < filers.list

# 3  
Old 09-01-2010
Code:
 awk '/running/{host=$1}/Path:/{path=$2;print host,path}' filers.list

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

2. Shell Programming and Scripting

awk question ? set 2 variables by matching fields

Hello, I'm trying to get the TOP and BASE numbers printed out File looks like this: 2300 CAR # 2300 is the TOP 2310 CAR 2335 CAR 2455 CAR # 2455 is the BASE 1000 MOTOR # 2455 will become this TOP 2000 MOTOR 3000 MOTOR 4000 MOTOR # 4000 is the BASE 2345 BIKE # 4000... (8 Replies)
Discussion started by: charlieglen
8 Replies

3. Shell Programming and Scripting

ksh passing to awk multiple dyanamic variables awk -v

Using ksh to call a function which has awk script embedded. It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Discussion started by: highnthemnts
1 Replies

4. Shell Programming and Scripting

awk question for printing variables

Hi All, I have the following awk code where I am passing 4 variables to the program and I need to print them in the awk script. The variables are $start_month $start_date - $end_month $end_date. printf("\tFor More Information\n") > out_tmp1 printf("\tIf you have any questions about this... (6 Replies)
Discussion started by: nua7
6 Replies

5. Shell Programming and Scripting

awk multiline matching

I have a file that looks something like this with lots of text before and after. Distance method: Sum of squared size difference (RST) </data> <pairwiseDifferenceMatrix time="02/08/11 at 13:08:27"> 1 2 1 448.82151 507.94231 2 ... (7 Replies)
Discussion started by: mgray
7 Replies

6. Shell Programming and Scripting

Multiline pattern search using sed or awk

Hi friends, Could you please help me to resolve the below issue. Input file :- <Node> <username>abc</username> <password>ABC</password> <Node> <Node> <username>xyz</username> <password>XYZ</password> <Node> <Node> <username>mnp</username> ... (3 Replies)
Discussion started by: haiksuresh
3 Replies

7. Shell Programming and Scripting

Awk match a multiline pattern

Hello! i wanna match in a config file, one text with more than one lines, something like this: CACHE_SIZE{ 10000 M } I have problems with the ends of line, i think that i can match the end of the line with \n, but i can't get it Someone can help me with the regular expression? ... (18 Replies)
Discussion started by: claw82
18 Replies

8. Shell Programming and Scripting

Awk Multiline Record Combine?

I'm trying to use Awk to get the id and name fields ($1 and $2) of file1 combined with their corresponding multiline records in file2 that are separated by blank line. Both files are ordered so that the first line of file1 corresponds to the first set of multiline records in file2 and so on. ... (4 Replies)
Discussion started by: RacerX
4 Replies

9. Shell Programming and Scripting

Awk/shell question: Read from file and assign to variables.

Is anyone able to help with writing a program that will do the following: 1. Read the contents of a file, line by line, and on each line, assign each of the two columns to a shell variable. 2. perform an action on the variables 3. Read the next line. Here is what I've gotten so far. ... (3 Replies)
Discussion started by: akbar
3 Replies

10. Shell Programming and Scripting

Awk Compare Files w/Multiline Records

I'm trying to compare the first column values in two different files that use a numerical value as the key and output the more meaningful value found in the second column of file1 in front of the matching line(s) in file2. My problem is that file2 has multiple records. For example given: FILE1... (4 Replies)
Discussion started by: RacerX
4 Replies
Login or Register to Ask a Question