Greetings everyone,

I'm very new to perl, so please don't laugh at my script ;-)
I wrote this script to login to my work box from home and change a hosts file to reflect my home ip address. I know there is a way to do this a lot quicker and prettier. This is really just a learning experience for me, so any input would be appreciated. I just started reading "Mastering Regular Expressions", so that's still pretty new to me. Anyway, here we go:


#!/usr/bin/perl


# Script to login to work machine and rewrite /$home/etc/hosts entry #there



use strict; use warnings;


use Net::SSH qw(sshopen2);


my $ppp0 = `/sbin/ifconfig ppp0`; $ppp0 =~ m/(\d+\.\d+\.\d+\.\d+)/; my $ip = $1;



my $user = "jrak";
my $host = "mail.myhost.org";
my $cmd = "perl -pi -e 's/^\\d+\\.\\d+\\.\\d+\\.\\d+\thome/$ip\thome/' /home/jrak/etc/hosts";





sshopen2("[EMAIL PROTECTED]", *READER, *WRITER, "$cmd") || die "ssh: $!";


while (<READER>) { chomp(); print "$_\n"; }

                                                       close(READER);
close(WRITER);



/home/jrak/etc/hosts file is always like this:
192.168.1.1     home



Thanks for any input you have,

-Jeff

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to