Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

One problem solved, another one arr

Status
Not open for further replies.

CarlPender

Technical User
Apr 25, 2003
12
IE
One problem solved, another one arrives..........


I have a Suse 7.3 Linux PC acting as a gateway for a wireless network. I have a script to allows users onto the network depending on their MAC addresses and another to stop them having access to the network.

What I want to do is let them onto to the network and then 5 hours later, log them off again. I was told to use something like this:

#!/bin/bash

/usr/local/apache/cgi-bin/add

sleep 18000

/usr/local/apache/cgi-bin/remove



This is no good to me because if I put the program to sleep it will lock up. I cant have it locking up because then if another user logs on the program wll be locked up so they wont be able to access the net.

Do you have any suggestions how to do this?

Thanking you in advance

Carl Pender
 
You need an event loop.
You can use tcl for this easily.
Using the shell you will not easily do this.

Something like this(untested):
Code:
#!/usr/bin/tclsh
set interval [expr [lindex $argv 0] * 1000] 
set start [clock scan "5 hours" -base [clock seconds]]

proc checktime {prog} {
global start interval end

       if {[clock seconds] >= $start} {
          exec $prog
          set end 1
       } else {
          after $interval {checktime $prog}
          return [clock seconds]
       }
}

exec firstprog
after $interval {checktime}
vwait end
 
Thanks for that!

I'm sorry about this but I dont really understand what the program is actually doing or how to call it.

Also how do you vary fo different intervals?

How do I call my scripts with this program?
 
You would pass an interval timeas the first arg to the program.
You could pass variable hour length as the second arg
or just code it statically.
The exec calls start the other programs.


You may also want to add a logging function
as a way to id the user being added and provide
some way to use the log to detect already 'on'
hosts to prevent multiple starts of the program.


HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top