#!/usr/local/bin/perl use strict; use warnings; ++$|; print "Starting dial program\n"; my $child; if ( $child = fork ) { print "Parent:\t$$\n"; sleep 20; # wait for wvdial to do login while ( 1 ) { sleep 1; last if netcheck(); # check if network is up } if (( proc_check($child) ) && ( netcheck())) { print "Do stuff\n"; system("fetchmail"); system("wget", "http://www.example.com"); } else { print "Something's wrong: q to get out of here"; } my $in = <>; # this is just a temporary end to the script for testing if ( $in eq 'q' ) { kill -2, $child; exit; } } else { ### CHILD print "Child\t$$\n"; system( "wvdial" ); } sub netcheck { my $net = `netstat -r`; if ( $net =~ m!ppp! ) { return 1; } else { return 0; } } # end netcheck sub proc_check { my $pid = shift; unless ( kill 0 => $pid ) { print "Process $pid died or something\n"; return 0; } return 1; } # end proc_check