LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-19-2005, 06:09 PM   #1
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Rep: Reputation: 15
A problem about a shell script


#!/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;


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

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.


anyone knows what's the problem?
 
Old 01-19-2005, 06:10 PM   #2
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Original Poster
Rep: Reputation: 15
actually i use a perl script the 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;
}


is the problem lying in this one, or in the shell script??

Jimmy
 
Old 01-19-2005, 06:14 PM   #3
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Original Poster
Rep: Reputation: 15
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Problem in shell script Kumar Programming 4 04-27-2004 08:48 AM
Shell-Script Problem? x4v013 Slackware 7 09-17-2003 12:15 AM
shell script problem steltner Linux - General 19 05-18-2003 02:42 PM
shell script problem steltner Programming 0 05-17-2003 03:26 PM


All times are GMT -5. The time now is 08:34 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration