Solved

Time connected

Posted on 1998-11-28
8
146 Views
Last Modified: 2010-03-04
I'm looking for a small script (I hope) that will track amount of time connected by a user from a list and if they exceeed a certian amount of time have them disconected.

I have a script that tracks time but I want it to only track certian users.(Script below)

The user list would be one user per line in a standard text file.

user1
user2
user3

******* START SCRIPT **********


    IW  checkm                        Row 1    Col 1   11:21  Ctrl-K H for help
#!/bin/sh                                                                      
#                                                                              
#  Check checks to see if any of the people who are logged in at the time      
# have used up their allotment of time (as specified by MAXHOURS) on the        
# modems (as specified by TTYS).                                                
#                                                                              
MAXHOURS=11.00
TTYS="ttyC0 ttyC1 ttyC2 ttyC3 ttyC4 ttyC5 ttyC6 ttyC7 ttyC8 ttyC9 ttyC10 ttyC11"

hours=`date +%H:%M:%S`
users=`users`                                                                  

u=`for x in $users; do echo $x; done | sort | uniq`                            

sac -pb $hours $u -T $TTYS | while read user hours                              
do                                                                              
  if [ `expr $hours '<=' $MAXHOURS` -eq 1 ]; then                              
    echo "$user is OK. ($hours)"                                                
#                                                                              
#    ps x | tail +2 | while read usr PID whatever
#    do                                                                        
#      if [ $usr = $user ]; then kill -9 $PID; fi                              
#    done                                                                      
#  fi                                                                          
  else                                                                          
    echo "$user is over the limit. ($hours)"                                    
  fi                                                                            
done                                                                            
# If you use Sac to implement usage limits, the above can be modified to        
# "logout" the user by modifing the above if statement to the below:            
#                                                                              
#  if [ `expr $h '<=' $MAXHOURS` -eq 0 ]; then                                  
#    echo "You're over the time limit bozo! ($h) Bye Bye!" | write $user        
#    ps augx | tail +2 | while read usr PID whatever                            
#    do                                                                        
#      if [ $usr = $user ]; then kill -9 $PID; fi                              
#    done                                                                      
#  fi                                                                          
#                                                                              
# Running this script every 5-10 minutes in a cron job wouldn't be a bad idea  
# either.
0
Comment
Question by:bross073097
  • 5
  • 2
8 Comments
 

Author Comment

by:bross073097
ID: 1206647
Edited text of question
0
 

Author Comment

by:bross073097
ID: 1206648
Edited text of question
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1206649
and what's the question
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:bross073097
ID: 1206650
Can some one help with this. I'm looking for this script to do a little more.
0
 
LVL 5

Expert Comment

by:thoellri
ID: 1206651
How about adding the following:

Change this code:
   users=`users`                                                                    
   u=`for x in $users; do echo $x; done | sort | uniq`

To:
   users=`users`                                                                    
   usernames=/etc/usernames.dat
   u=`for x in $users; do grep -wi "$x" $userfile 2>&1 > /dev/null ; if [ $? -eq 0 ] ; then ec
ho $x; fi; done | sort | uniq`        

And supply the usernames you want to check for in the file /etc/usernames.dat (one username per line). If the username from `users` appears in the file, then it will be included in $u, otherwise it is dropped. Change $usernames to another filename, if you don't like /etc/usernames.dat.

And ... consider changing to perl :-)
  Tobias

0
 

Author Comment

by:bross073097
ID: 1206652
OK thanks, do you have something in perl?, that can do this.

I will clear this off shortly.

My email address is bross@kingman.com

Thanks
Bob Ross

0
 

Author Comment

by:bross073097
ID: 1206653
I was going to give you the points but there is not an option to do this.

Thanks
Bob Ross

0
 
LVL 5

Accepted Solution

by:
thoellri earned 90 total points
ID: 1206654
Blank answer for the points :-)

No I don't have anything handy, but it shouldn't be too difficult to rewrite it in perl. I assumed you knew perl by posting your question to the perl-area.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

860 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