UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old October 19th, 2004, 08:39 AM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 31 m 24 sec
Reputation Power: 15
Here docs with ssh

I'm trying to write a little utility that'll connect to a number of boxes on my network, collect some system information, store them in local text files, then update a database with that information.

At the moment, I'm trying to work out the ssh issues.

It was recommended to me to use here docs to pass a lot of commands to the ssh command for remote execution.
Unfortunately, when using that it seems to execute the commands before the connection is established, as all the commands fail.

Here's my code:
Code:
while read linevar
do
        ssh -n cunnings@${linevar} hostname <<END_OF_SSH
        echo "Connected to $linevar!"

        ### Obtain system information ###

        node=$(uname -n | tr '[A-Z]' '[a-z]')
        os=$(uname)

        if test $os = AIX ; then
           osv=`oslevel`
           ip=$(ping -a -c1 $linevar | head -1 | awk '{print $3}' | tr -d ":")
           mem=$(lsattr -E -l mem0 | tail -1 | awk '{print $2}')
           cpus=$(lscfg | grep proc | wc -l | awk '{print $1}')
        fi
        if test $os = SunOS ; then
           osv=`uname -r`
           ip=$(ping -a -c1 dingo | head -1 | awk '{print $2}')
           mem=$(/usr/sbin/prtconf | grep 'Memory size' | awk '{print $3}')
           cpus=$(/usr/sbin/psrinfo | wc -l | awk '{print $1}')
        fi
        if test $os = Linux ; then
           osv=`uname -r`
           ip=$(ping -c1 $linevar | head -1 | awk '{print $3}' | tr -d ":")
           mem=$(grep MemTotal /proc/meminfo | tail -1 | awk '{print $2}')
           cpus=$(cat /proc/cpuinfo | grep ^processor| wc -l | awk '{print $1}')
           let "mem = $mem / 1024"
        fi

        if test -r ../data/node_details.txt ; then
                rm ../data/node_details.txt
        else
                touch ../data/node_details.txt
        fi

        echo "Node name   :  $node" >> node_details.txt
        echo "OS Name     :  $os" >> node_details.txt
        echo "OS Version  :  $osv" >> node_details.txt
        echo "IP Address  :  $ip" >> node_details.txt
        echo "Memory      :  $mem MB" >> node_details.txt
        echo "CPU Count   :  $cpus" >> node_details.txt

END_OF_SSH
done < node_list.txt

And here's the output (note: username is just a substitution for my own username):
Code:
/home/username/usc/scripts/usc_main: oslevel: command not found
ping: invalid option -- a
Usage: ping [-LRUbdfnqrvV] [-c count] [-i interval] [-w wait]
        [-p pattern] [-s packetsize] [-t ttl] [-I interface address]
        [ -T timestamp option ] [ -Q tos ] host
lsattr: invalid option -- E
Usage: lsattr [-RVadlv] [files...]
/home/username/usc/scripts/usc_main: lscfg: command not found
ping: invalid option -- a
Usage: ping [-LRUbdfnqrvV] [-c count] [-i interval] [-w wait]
        [-p pattern] [-s packetsize] [-t ttl] [-I interface address]
        [ -T timestamp option ] [ -Q tos ] host
/home/username/usc/scripts/usc_main: /usr/sbin/prtconf: No such file or directory
/home/username/usc/scripts/usc_main: /usr/sbin/psrinfo: No such file or directory
username@lightning2's password:
lightning2
/home/username/usc/scripts/usc_main: oslevel: command not found
ping: invalid option -- a
Usage: ping [-LRUbdfnqrvV] [-c count] [-i interval] [-w wait]
        [-p pattern] [-s packetsize] [-t ttl] [-I interface address]
        [ -T timestamp option ] [ -Q tos ] host
lsattr: invalid option -- E
Usage: lsattr [-RVadlv] [files...]
/home/username/usc/scripts/usc_main: lscfg: command not found
ping: invalid option -- a
Usage: ping [-LRUbdfnqrvV] [-c count] [-i interval] [-w wait]
        [-p pattern] [-s packetsize] [-t ttl] [-I interface address]
        [ -T timestamp option ] [ -Q tos ] host
/home/username/usc/scripts/usc_main: /usr/sbin/prtconf: No such file or directory
/home/username/usc/scripts/usc_main: /usr/sbin/psrinfo: No such file or directory
username@ranger's password:
ranger

The text file being read in contains 2 lines:
LIGHTNING2
RANGER

I'm running the script on RH, under the korn and/or bash.
__________________


Webinfractions.com
Think I'm wrong? You're probably right!

Reply With Quote
  #2  
Old October 22nd, 2004, 09:18 AM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 31 m 24 sec
Reputation Power: 15
Would a mod please close this, it's in the wrong forum.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Here docs with ssh


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway