Solved

Time connected

Posted on 1998-11-28
8
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans

617 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