The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 09:12 PM
Embedding xnest in C code lesnaubr High Level Programming 4 08-13-2007 03:27 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl SuSE 5 07-30-2007 09:26 AM
Embedding Perl construct in ksh... svetlur Shell Programming and Scripting 1 06-07-2007 10:39 PM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr Shell Programming and Scripting 0 09-19-2006 10:44 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 07-12-2008
hcclnoodles hcclnoodles is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 272
Embedding a command with SSH

Hi

I am trying to run a script centrally that will go out and set the network management ip address on all my Sun boxes running Solaris. We have decided that the network management address will be the boxes main IP address but the first octet as a 172 rather than a 10, so for example ifconfig -a will look like this

Code:
[root@a-server # ifconfig -a
lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000
dmfe0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
        inet 10.36.14.45 netmask ffff0000 broadcast 10.32.255.255
        ether 0:3:ba:5:a8:1a
the command to set the management IP address locally on these machines would be

Code:
/usr/sfw/bin/ipmitool -I bmc lan set 1 ipaddr 172.36.14.45
so I have written a little script that and will do a sed replace against the output of ifconfig, switch the 10 for a 172 blah blah and throw the output into the ipmitool command listed above, and when run locally on the target machine it works like a dream ...here it is

Code:
/usr/sfw/bin/ipmitool -I bmc lan set 1 ipaddr `ifconfig -a | grep inet | grep -v 127.0.0.1 | head -1 | sed s/^.*inet\ // | sed s/\ netmask.*$// | sed s/^10/172/`

So as I say, rather than running this on every box locally, ive written another script that goes out to all machines (listed in a file called serverlist) using SSH and sets it remotely, the problem is, when I do this, the embedded ifconfig/sed bit seems to run locally on my central servers IP address and not on the target box, so in other words it sets the remote boxes management IP to my central boxes main IP (with the 10 switched for a 172) ....I just cant seem to get it to properly embed and run the command on the target box

here is my script


Code:
#!/bin/ksh

for hostname in `cat /data/serverlist`
do

       echo $hostname
       ssh $hostname "/usr/sfw/bin/ipmitool -I bmc lan set 1 ipaddr `ifconfig -a | grep inet | grep -v 127.0.0.1 | head -1 | sed s/^.*inet\ // | sed s/\ netmask.*$// | sed s/^10/172/`"

done
When run ...

Code:
[root@central-server] # ./configure.sh
a-server
Setting LAN IP Address to 172.1.0.45  << this should be 172.36.14.45
does anybody know why this is happening....ive tried changing the " for a ' but then it stops working altogether

any help would be greatly appreciated
 

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0