Solved

Time connected

Posted on 1998-11-28
8
137 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
Comment Utility
Edited text of question
0
 

Author Comment

by:bross073097
Comment Utility
Edited text of question
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
and what's the question
0
 

Author Comment

by:bross073097
Comment Utility
Can some one help with this. I'm looking for this script to do a little more.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Expert Comment

by:thoellri
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 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

11 Experts available now in Live!

Get 1:1 Help Now