- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ssh within a script not working for some reason
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2010 05:47 AM
01-13-2010 05:47 AM
The point of the following script is to go out to all our servers and if the /var/mail/root file is current (today's date); then tail the last 100 lines to a file. Then send me the file. Now out of the whole list, there are about 8 servers that have a current mail log. However, my script is only outputting the first entry. If I just "echo $a" it will echo all servers with a current date....but when I ssh $a and tail the mail log it stops after the first one.
#! /usr/bin/ksh
m=`date +%b`
d=`date +%e`
HOME=/home/me/scripts
LIST=$HOME/serverlists/all.servers
OUT=/home/me/tmp/mail.out
OUT2=/home/me/tmp/maildat.out
MAIL=/var/mail/root
MAILLIST=me@example.com
if [ -f $OUT ]; then rm $OUT; fi
if [ -f $OUT2 ]; then rm $OUT2; fi
for x in `cat $LIST`; do
echo "$x \t `ssh $x ls -la $MAIL |awk '{print $6, $7}'`" >>$OUT2
done
cat $OUT2| while read a b c
do
if [ $b = $m ] && [ $c -eq $d ]; then
echo "_________________________________________________________________________\n" >>$OUT
echo "\n $a \n" >>$OUT
echo "_________________________________________________________________________\n" >>$OUT
ssh $a "tail -100 $MAIL" >>$OUT
fi
done
cat $OUT |mailx -s "MAIL Log" $MAILLIST
Solved! Go to Solution.
- Tags:
- ssh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2010 06:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2010 06:17 AM
01-13-2010 06:17 AM
Re: ssh within a script not working for some reason
In addition to adding the '-n' to your 'ssh' as Bill noted, change:
for x in `cat $LIST`; do
echo "$x \t `ssh $x ls -la $MAIL |awk '{print $6, $7}'`" >>$OUT2
done
...to:
while read x
do
echo "$x \t $(ssh -n $x ls -la $MAIL|awk '{print $6, $7}')"
done < ${LIST} > ${OUT2}
This eliminates the extra 'cat' process letting the shell do the read of the input file. The code also uses the Posix '$()' notation instead of the backticks to run a command. This is much more readable.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2010 06:20 AM
01-13-2010 06:20 AM
Re: ssh within a script not working for some reason
debug:
ssh -vvv
redirect the output to a file so you can see the error message.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2010 06:27 AM
01-13-2010 06:27 AM