Solved

Time connected

Posted on 1998-11-28
8
142 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 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

13 Experts available now in Live!

Get 1:1 Help Now