Operating System - HP-UX
1834413 Members
1949 Online
110067 Solutions
New Discussion

Re: Dynamically Generate New Files with new o/p

 
SOLVED
Go to solution
panchpan
Regular Advisor

Dynamically Generate New Files with new o/p

for serv_cnt in `cat /home/mfgeb/pp/serv.txt`
do
j=$serv_cnt
echo "===[ Directory List for Server: $serv_cnt ]==="
ssh $serv_cnt "find /mfgdata/ -type d -exec ls -ld {} \; 2>/dev/null "
done >> $j.mfgdata-ux-dir.ls

How can I dynamically generated output file with differnt names??? Here $j does not seem to taking it correctly.
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Dynamically Generate New Files with new o/p

I would change it to something like this:

#!/usr/bin/sh

typeset serv_cnt=""

cat /home/mfgeb/pp/serv.txt | while read serv_cnt
do

echo "===[ Directory List for Server: $serv_cnt ]==="
ssh $serv_cnt "find /mfgdata/ -type d -exec ls -ld {} \; 2>/dev/null " >> "${serv_cnt}.mfgdata-ux-dir.ls"
done

If it ain't broke, I can fix that.
spex
Honored Contributor

Re: Dynamically Generate New Files with new o/p

for serv_cnt in $(cat /home/mfgeb/pp/serv.txt)
do
OF=${serv_cnt}.mfgdata-ux-dir.ls
echo "===[ Directory List for Server: $serv_cnt ]===" > ${OF}
ssh ${serv_cnt} "find /mfgdata -type d -exec ls -ld {} \; 2>/dev/null" >> ${OF}
done
Sandman!
Honored Contributor

Re: Dynamically Generate New Files with new o/p

Are you getting any errors when trying to ssh to run the find command?



Peter Nikitka
Honored Contributor

Re: Dynamically Generate New Files with new o/p

Hi,

I don't know what the rest of your loop is doing, but having started the ssh without closing its input/output, it be be cannibalizing the 'for .. in'. Execute always 'ssh -n' in that cases.
So try (more modification included):

while read j
do
print "===[ Directory List for Server: $j ]==="
ssh -n $j 'find /mfgdata -type d 2>/dev/null |
xargs ls -ld' >>$j.mfgdata-ux-dir.ls
...
done
mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"