Specified log in time for users


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Specified log in time for users
# 1  
Old 06-17-2012
Specified log in time for users

I have this task : Check the logintime.txt every minute to only allow user to log in at the specified time.

logintime.txt has the following content: USER TIME_START TIME_STOP
Example:
Code:
 
john 17:00 18:00

My idea is locking the user at the TIME_STOP and unlocking at the TIME_START

Code:
while read line
do
USER=$(echo $line | awk '{print $1}')
TIME_START=$(echo $line | awk '{print $2}')
TIME_STOP=$(echo $line | awk '{print $3}')
at $TIME_START << EOF
passwd -l $USER
EOF
at $TIME_STOP << WTH
passwd -u $USER
WTH
done < logintime.txt

Any better idea to do this? Because my solution don't do the 'check file every minute' thing. And I don't understand why we need to do that thing.
# 2  
Old 06-17-2012
Quote:
Originally Posted by muffle
I have this task : Check the logintime.txt every minute to only allow user to log in at the specified time.

Any better idea to do this? Because my solution don't do the 'check file every minute' thing. And I don't understand why we need to do that thing.
Code:
while read USER TIME_START TIME_STOP # Get rid of echo and awk by using shell's IFS
do
at $TIME_START << EOF
passwd -l $USER
EOF
at $TIME_STOP << WTH
passwd -u $USER
WTH
sleep 60 # This should let a minute pass
done < logintime.txt

Quote:
Originally Posted by muffle
And I don't understand why we need to do that thing.
Well, isn't that your requirement?
# 3  
Old 06-17-2012
my boss's requirement. About sleep 60, isn't it only runs the while loop every 60 seconds when we run the script ?
# 4  
Old 06-18-2012
The checking every minute bit seems unnecessary.

Do you need to kill the session(s) which are active in that user's closed period? Even then you could issue an "at" job at the appropriate time.

It may mean the person specifying the script did not know about Linux unix "at" command or about special options to "passwd" on certain Linux platforms (it won't work on unix).

@balajesuri
I can't see the point of your sleep unless there is an issue with the number of concurrent "at" jobs. Also, if there list is very long the script could take hours to run.
# 5  
Old 06-18-2012
I've figured it out myself.

Checking every minute to get the current time. If it is = TIME_STOP, kill the session of that user (use pkill -KILL -u username) and also lock the username

Thanks for your reply.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problems in analysing SSH LOG users & time

Attached is the log file that I have generated through the following script: last | head -2 |sed '2q;d' |awk '{ print $1"\t"$2"\t"$3"\t\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t" $9"\t"$10"\t"$11}'>>/var/log/logadmin/logtest.txt But now I'm unable to run the following operations on it: 1. Count... (1 Reply)
Discussion started by: Lionking93
1 Replies

2. Homework & Coursework Questions

Sort current logged in users by log in time (supposedly to be very easy but I'm missing something)

1. The problem statement, all variables and given/known data: Show all users who are currently logged in, sorted from earliest to latest log in time. The log in time includes the month, day, and time. 2. Relevant commands, code, scripts, algorithms: finger, who, sort, pipe, head, tail, ... (8 Replies)
Discussion started by: vtmd
8 Replies

3. Shell Programming and Scripting

id -a multiple users at one time?

Hi Expert, How do I want to id -a multiple users at one time? * i know that this does not work, Thanks (4 Replies)
Discussion started by: regmaster
4 Replies

4. Shell Programming and Scripting

Monitoring a users log in time?

how do i start with this guys? Sample run: $ LOGTIME it2015678 <enter> User it2015678 is CRUZ Tommy H And has logged on to the system for: 8 hours 12 minutes from the time this script was run. (1 Reply)
Discussion started by: skypigeon
1 Replies

5. UNIX for Dummies Questions & Answers

Date, time, users

i need to find out following ways to show out put in a shell script when the user selects that option in a case statement. I have the case statement already started just need to find out how to read the following: current date and time (should it be read date)? users logged in (should it be... (4 Replies)
Discussion started by: vthokiefan
4 Replies

6. UNIX for Advanced & Expert Users

same file being opened by two users at a time

I want to avoid a situation where because two users simultaneously open a file and modify and save, leaving the original file in mess. Is there a way in UNIX to warn a user if that particular file is already being used by another user. Thanks in advance (3 Replies)
Discussion started by: paresh n doshi
3 Replies

7. Programming

how can get users list and their login time?

i'm sorry if yesterday i posted this thread in unix for dummies forums, :D i am a newbie in C programming i want to get active users list and their login time... i have search and learn about passwd and utmp, but i only can get user list without their login time... do you have an idea... (2 Replies)
Discussion started by: alif
2 Replies

8. UNIX for Dummies Questions & Answers

last login date and time for all users

I need a command that will list all the users and their last login date & time. I was trying the last command and the who command, but can't get exactly what I need. I just need the output to be user name and last login date . Thanks for your help! (3 Replies)
Discussion started by: igidttam
3 Replies

9. UNIX for Dummies Questions & Answers

log users real time

hi.... how i can configurator a log file on real time....on unix solaris.... thanks a lot.... Best Regards... (3 Replies)
Discussion started by: chanfle
3 Replies

10. UNIX for Dummies Questions & Answers

Finding last time users logged in

I would like to find out the last time all users have logged in or out. I tried the last command, but it could not find the wtmp file in /var/adm (I searched in othe directories also). This is an AIX rs6000 4.2.1 system. We are moving our applications from this system to an AIX 5.2 system and I... (11 Replies)
Discussion started by: jyoung
11 Replies
Login or Register to Ask a Question