nascent has asked for the wisdom of the Perl Monks concerning the following question:

My phone lines have just gone from bad to worse. How hard would it be to have a bit of perl that looks for a valid ppp0 in ifconfig and reconnects if it fails to see one?

Pardon if this streches well into cron-land, since I'm learning perl that's how I wanted to approach it.

- nascent

Replies are listed 'Best First'.
RE: compound perl question
by Dominus (Parson) on Mar 12, 2000 at 02:02 UTC

    It would be pretty easy, but I think it makes mose sense to just run pppd from loop inside a perl program:

    	while ('true') {
    	  system("pppd ...");
    	  print STDERR "pppd exited; restarting...\n";
    	}
    

    That's what I do on my system, except my script has some logging and it has some safety features so that it doesn't spin out of control if I shut off the modem or something like that.

      In my infinite newbie-ness, it appears that this will just echo back that it has exited and will restart ...but doesn't actually *do* that.

      Am I applying the wrong tools (perl) for this job?

      thx,
      nascent

        You might be thinking of the exec command. Take a look at system. It actually forks off the system call, and then the parent waits for the child to exit before proceeding. When pppd exits, the parent process will print the error message, hit the end of the loop, and repeat.

        With your original question, I would do something like: my $ifconfig_data = `/sbin/ifconfig ppp0`; and then use a regexp to look for a valid IP address or whatever you like.