Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Time connected

Posted on 1998-11-28
8
Medium Priority
?
156 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 360 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

Hire Technology Freelancers with Gigs

Work with 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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

721 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