the following is the content of the shell script, /bin/setip written by me.


#!/bin/bash

PATH="$PATH:/bin:/sbin";
export PATH;
let gw=255-$1

net_file=/etc/network/interfaces
host_file=/etc/hostname

# change ip address and gateway of the UML
cat $net_file | sed "s/address 192.168.1.*/address 192.168.1.$1/" > $net_file
cat $net_file | sed "s/gateway 192.168.1.*/gateway 192.168.1.$gw/" > $net_file


# change hostname of the UML
echo uml_woody_$1 > $host_file

#reboot the UML
reboot

exit 0;

-------------------------------------------------------------------------

and I'm using the following Perl script to remotely execute the shell script i

mentioned above. Here's the content of the perl script, config_net.pl:

#!/usr/bin/perl

$| = 1;

use Net::SSH::Perl;
use Net::SCP::Expect;

die "Usage: $0 LAST_OCTECT\n" if (!$ARGV[0]);

$oldip = '192.168.1.127';
print "Running /bin/setip $ARGV[0]\n";

while ($error = Rpc($oldip, "/bin/setip $ARGV[0]")) {
print "UML not up yet. $error\n";
sleep 2;
}

###############################################################################

sub Rpc {
my ($host,$cmd) = @_;
my $ssh;
print "Starting SSH\n";
eval { $ssh = Net::SSH::Perl->new($host, ['debug' => 'yes',]); };
if ($@) {
return "Failed to connect\n$@";
}
print "Logging into $host\n";
$ssh->login('root', 'root');

my ($stdout, $stderr, $exit) = $ssh->cmd($cmd);
print "Output: $stdout\n";
print "Error: $stderr\n";
return $exit;
}

moreover, they way i use config_net.pl to remotely execute /bin/setip is like:

$config_net.pl uml_number

where uml_number is a number like 11


i found that SOMETIMES after i execute the script remotely, the file /etc/network/interfaces will be totally cleared, which is not my purpose. But, SOMETIMES it works very well.

I wonder where's the problem? is it on the schell script, or the perl script??





--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.1 - Release Date: 1/19/2005



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
User-mode-linux-user mailing list
User-mode-linux-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-user

Reply via email to