Operating System - HP-UX
1833599 Members
3859 Online
110061 Solutions
New Discussion

Output from several SSH server's several files into single file

 
panchpan
Regular Advisor

Output from several SSH server's several files into single file

I have 2 input files - has server names and its residing db names in them. Now I would like to go to each server (from 1st file) and then to one of server's db (from 2nd file). Then to a particular path and to store contents of some files from this path to another file. This task is needed for all (~500) dbs of all (~10) Servers. Below is kinda prototype:

1) ssh
2) go [will take to the directory of selected db from second file]
3) cdpf [will take to the directory from where i need output]
4) cat a*pst.pf >> outofpf.lst
5) ssh
...

Please advice how can it be done efficiently.

Thank you!
3 REPLIES 3
Sandman!
Honored Contributor

Re: Output from several SSH server's several files into single file

How do you know which DB is on which server. The two input files need to be joined on a common field or some sort of correlation has to exist between the two in order to make this viable. Could you provide a sample listing of the contents of the two input files.
panchpan
Regular Advisor

Re: Output from several SSH server's several files into single file

Actually, I was wrong. I have only one input file - which has entries of db names. E.g. 001
002
003

The script I had tried with is:
for db_cnt in `cat /home/mfgeb/pp/db-file.txt`
do
go $db_cnt "cdpf;
head -8 a*`$db_cnt`pst.pf" >> db.out;
done

db-file : Has names of databases. There is one inbuilt script I have 'go' which takes to the corresponding server of supplied DB. Its like ssh command. But ssh command works only with server name. go command can have input of only db name and then it will internally figure out its server name and then ssh to that server. Then 'cdpf' is the script which will change directory to a specific path. From that directory I want values of some files and to be kept them stored in some output file for all DBs.

Pls suggest!
Doug O'Leary
Honored Contributor

Re: Output from several SSH server's several files into single file

Hey;

I'm not real clear on what you're trying to do. It looks like you're trying to get the first 8 lines of a particular file from a list of servers. Let me know if that's accurate.

In command execution mode, ssh typically has a very limited environment. Not as limited as cron, for instance, but still, not what you get when you fully log into the box. Therefore, if "go" isn't in /usr/bin or /bin, ssh probably won't find it.

Your best bet would be to create a datafile such as:

Host1 DB1 path_to_pst.pf
Host1 DB2 path_to_pst.pf
Host2 DB3 path_to_pst.pf
Host3 DB4 path_to_pst.pf

from that:

cat ${data_file} | while read h d p
do
ssh -n ${h} "head -8 ${p}/a*${d}" >> outofpf.lst
done

You'll need the -n option on the ssh call because of the cat file | while read construct. You'll get errors otherwise.

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html