Solved

time limit the connection

Posted on 2000-02-19
8
237 Views
Last Modified: 2013-12-06
Hello, How do I configure PPP so that every X minutes it will disconnect, and reconnect again?
0
Comment
Question by:mlvn23
8 Comments
 
LVL 3

Accepted Solution

by:
freesource earned 50 total points
ID: 2539049
You could run a script to accomplish this.  I use "pon" and to connect, just replace this script with the command you use in the script below.  For Red Hat you would want to use "usernetctl ppp0 up" in place of pon.

#!/usr/bin/perl

# This program is under the GNU GPL by freesource at
#  http://the.netpedia.net/the-software.html
#  For Red Hat you would want to use "usernetctl ppp0 up" in place of pon.

print "usage: command second(s)\n" if $#ARGV == -1;
exit if $#ARGV == -1;

$connection = "pon"; # fill in the appropriate thing
system "$connection";  # turn it on

if ($ARGV[0] <= 59) {  # it takes this long just to dial and connect
   print "I need more time, at least 60 seconds\n"; exit;
}

while () {  # endless loop issuing HUP to process
     sleep $ARGV[0];
     system "kill INT `cat /var/run/ppp*pid` 2>/dev/null"; # just kill the pppd process  
     sleep 10;  system "$connection"; # restart it, wait a while just to make sure
}
0
 

Author Comment

by:mlvn23
ID: 2542254
hmmm, what's pon and usernetctl?
0
 
LVL 2

Expert Comment

by:EatEmAndSmile
ID: 2542316
Ok, why do you want that?
0
 
LVL 3

Expert Comment

by:freesource
ID: 2543598
Actually, you don't need either pon or usernetctl .. you could use ppp-on which comes standard with ppp.

You can do a:

$ which pon
/usr/bin/pon
$ which usernetctl
$ which ppp-on
$ cat /usr/bin/pon
#!/bin/sh
/usr/sbin/pppd call ${1:-provider}

ppp-on on my system is found in ->
/usr/doc/ppp/examples/ppp-on

... or you could write your own script perhaps using ppp-on as a guideline to create a script to start up pppd .. then just replace pon in the script above with the script name you use to start your connection.

pon is found on Debian systems and usernetctl is usually found on Red Hat based systems.

I should point out two things about my script.  First, if you want it to be exactly a minute interval, edit the line which says "$ARGV[0] <= 59" to $ARGV[0] <= 49".  Then if you want 3 minute intervals go "name_you_give_the_script 170".  I leave 10 seconds to allow the modem to reset after it disconnects.  You may have to adjust these values, it just depends on your modem.

Secondly, if your modem gets disconnected by your service provider, this script will reconnect it .. so you get a bonus!
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 3

Expert Comment

by:jyu_88
ID: 2543650
If its not your ISP who disconnect your connection, then, a setup with 'diald' would probably make more sense.
0
 

Author Comment

by:mlvn23
ID: 2546374
iyu 88: actually it's my ISP - specifically it's my University's policiy to disconnect all ppp connections every 30 min. as to give others chance in connecting. So I would like to disconnect on the 29th min bec. for some weird reason, ppp doesn't die on the 30th min even though the server already hung up - Others can steal the resources. BTW: the reason why I stick with my university's internet service is bec. it outperforms most commercial ISP in my country :) but only a handful of dial-up numbers  (no trunk lines) are available.
0
 

Author Comment

by:mlvn23
ID: 2560986
freesource:

   I script works but how do I use it in conjunction with a PPP script that I wrote using KPPP? And how do you stop the script after it gets executed?
0
 
LVL 3

Expert Comment

by:freesource
ID: 2561166
What you need to do is find out how kppp executes the pppd script.

Doing a "ps auxw | grep pppd", would show me that  "/usr/sbin/pppd call provider" is used for the connection.

Then instead of pon, just edit the script so it looks like this:

$connection = "/usr/sbin/pppd call provider"; # fill in the appropriate thing

You should be about to find pppd, but if you can't just do a "ps auxw | less" and scan for something that looks like it executes the connection.

There several ways to kill the script.
If the script isn't running in the background just do [Ctrl]-[C].  If it is running in the background find out which job are running with "jobs" like this:

linuxalive:/etc/ppp/peers$ jobs
[2]+  Running                 pingy & 
linuxalive:/etc/ppp/peers$ kill %2

You can do this:
linuxalive:/etc/ppp/peers$ ps auxw | grep pingy
root      6945  0.1  1.5  2204   948  p5 S    13:08   0:00 perl /usr/sbin/pingy
linuxalive:/etc/ppp/peers$ kill 6945

You could get more sophisticated, too, but I think these methods should suffice.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
change time in cron 4 65
Determine Who is Runnig my Bash Shell Script 4 61
I think my Ubuntu 12.10 box is hacked, but not sure... 13 50
AWS CLI - Issue with name display 2 47
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now