use awk to ssh from variable in flat file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting use awk to ssh from variable in flat file
# 1  
Old 08-27-2010
use awk to ssh from variable in flat file

flat file looks like
ooss-pfgg-1234,vol_name_1, mail-list

decoded =
hostname,volum_name,mail_list
each line has diff info
am trying to ssh into each fist field, check vol usage for second field, and if greater than 90% send mail to mail-list

got the second and third part working,

first part am stumped

for i in `cat list.csv`; do ssh `awk 'FS="[, ]" {print $1}'` ; ????

how do i get the ssh command to pick up the awk variable ?
# 2  
Old 08-27-2010
You're on the right track. This should be enough of an example. Replace the date command with whatever you need to execute on the other side.

Code:
#!/usr/bin/env ksh 
awk  -F, '{print $1}' your-csv-file-name | while read host
do
        ssh $host date
done

I believe that this only works in ksh; bash has issues reading from a pipe into a variable. For bash you will probably have to do something like this:

Code:
for host in $( awk  -F, '{print $1}' file )
do 
      ssh $host date
done

This has potential problems if the number of host names in file becomes too large to be supported as a list of arguments for the for command. My recommendation is to go with Kshell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete line from remote file over ssh passing variable

I have a variable called $a1 which maps to something like "http://servername proxy1 count http" and a lots of entries in a file on remote server. If I have the following in my .sh script: sed -i "\%$a1%d" mylog.txtthe line is deleted from mylog.txt. Great. I'm trying now to remvoe this from a... (3 Replies)
Discussion started by: say170
3 Replies

2. Shell Programming and Scripting

Grepping the file into a variable after SSH into a server

Hi All, When i am logged into a server , i am able to assign grep value to a variable as follows. VAR=`grep 'Listener stopped' /logs/perf.log` However, when i log out of the server, and try to execute the following command by first SSHing into server, it throws error. $ VAR=`ssh Server... (4 Replies)
Discussion started by: srkmish
4 Replies

3. Shell Programming and Scripting

awk Flat File Conversion Script

In awk how would I flatten input.txt to output.txt? Input: givenname: Darth sn: Vadar mail: d.vadar@deathstar.com uid: dv12345 orclguid: 1234567890 givenname: Carlito sn: Brigante mail: c.brigante@paradise.com uid: cb12345 orclguid: 2134567890 Output: ... (3 Replies)
Discussion started by: u20sr
3 Replies

4. Shell Programming and Scripting

awk to place value at 24 field in a flat file issue

I am trying to add 0393 value at 24th feild using the below command, but its adding at all the lines including header and trailer Input file: ZHV|2657|D0217001|T|TXU|Z|PAN|20131112000552||||OPER| 754|52479| 492|489|SP40|1014570286334|20131111|20131201|14355334|CHAMELON... (1 Reply)
Discussion started by: Aditya_001
1 Replies

5. Shell Programming and Scripting

awk to delete fields from flat file

I would like to know awk command to delete the specific feild from a flat file delimited by '|' if the first feild starts with 354 I tried awk 'BEGIN {FS=OFS="|"} {$16=""; sub(/\|/, "")}'1 Input file: 354|||||GROUND||97||JUDD STREET|||LONDON||WC1H 9JG|ADI001| 354|||||FLAT 1... (10 Replies)
Discussion started by: Aditya_001
10 Replies

6. Shell Programming and Scripting

SED | Awk flat file one liner

sed awk one liner (2 Replies)
Discussion started by: jap2614
2 Replies

7. Shell Programming and Scripting

awk to compare flat files and print output to another file

Hello, I am strugling from quite a some time to compare flat files with over 1 million records could anyone please help me. I want to compare two pipe delimited flat files, file1 with file2 and output the unmatched rows from file2 in file3 Sample File1: ... (9 Replies)
Discussion started by: suhaeb
9 Replies

8. Shell Programming and Scripting

setting a variable, using SSH and awk?

hi there I am trying to get a value from a remote machine into a local variable. To get this value i want to use awk but im having trouble getting it to run, am i escaping in the right places here and using the right quotes (i must have tried a million combinations :() # VAR=`ssh server1... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

9. Shell Programming and Scripting

awk using ssh variable?

I have a file named Atoms that has a list of atoms listed vertically, like: O C Na etc. There is a variable number of them. I want to count their occurences in another file. I want to do this by saving each atom as a variable, preferabbly in an associative array, then counting how... (3 Replies)
Discussion started by: RisingSun
3 Replies

10. Shell Programming and Scripting

Awk to convert a flat file to CSV file

Hi , I have a file with contents as below: Contract Cancellation Report UARCNCL LOS CODE DATE REAS TYPE AMOUNT AMOUNT LETTER BY ========= ======= ==== ==== ==== ========= ==== ==== 8174739 7641509 1S NONE CRCD 30-JUN-2008 NPAR N .00 .00 CCAN 8678696 8091709 1S NONE DDEB 30-JUN-2008... (14 Replies)
Discussion started by: rkumudha
14 Replies
Login or Register to Ask a Question