Hello.
I've put together a few commands in a Perl script that does two things:
1. Tries to maintain a steady net connection (using PPPoE) 2. Resumes a download if it was interrupted because of a break in the net connection.
I am attaching the script here; any suggestions to make it more robust and generalized would be helpful. The wrapping makes it harder to read though.
<script> #!/usr/bin/perl -w
use strict;
# variables my $ppp0 = ''; my $pppd = ''; my $wget = ''; my $url = "http://ftp.science.nus.edu.sg/linux/ubuntu-ISO/edgy/ubuntu-6.10-alternate-am..."; my $iso = "/home/rohit/download/iso/ubuntu-6.10-alternate-amd64.iso";
while (1) { # check for ppp0 $ppp0 = `/sbin/ifconfig | /bin/grep ppp0`;
if ($ppp0 =~ /^ppp0/) { # Connection exists. # if ppp0 was down earlier, maybe our download got interrupted? $wget = `/bin/ps cax | /bin/grep wget`; unless ($wget =~ /wget/) { system("/usr/bin/wget -q -c $url -O $iso &"); } next; } # check for pppd $pppd = `/bin/ps cax | /bin/grep pppd`; if ($pppd =~ /pppd/) { next; # pppd is trying to get ppp0 up!! } # uh oh! we need to kill pppd # and launch the connection again system ("/usr/bin/killall -9 pppd"); system ("/usr/bin/pon dsl-provider"); #print "\a"; # remove this if the script works!! system ("sleep 60"); # Wait for 60 seconds }
# end of script </script>
Feedback appreciated.