Login loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Login loop
# 1  
Old 08-24-2009
Login loop

Hi!
I'm writing a program that test wich users are on
Code:
 
who | cut -d' ' -f1 > users

echo "The current users are: "
sort users 


then enters a loop that will wait 5 seconds then test which users are on then compare it to who was on before. If no one has logged on or off it will echo "no one has logged on/off" but if somebody has it will echo their username and "has logged on" or their username "has logged off"
So far I have:
Code:
 
while true
do
sleep 5
who | cut -d' ' -f1 > 5secs
sort 5secs >/dev/null
#???
cmp users 5secs
if [$? -eq 0]
then
echo "No users have logged in/off in the past 5seconds"
else
diff users 5secs
#???

5secs > users
done  

but I'm not sure if theat's how to correctly use the cmp method to test for differences. Also I have no idea how to use diff to compare the two correctly and return if users have been added or removed and what their names are.
Can anyone help me to figure out how diff can be used this way? Or is there another command to use?
any help with these would be appreciated Smilie

Last edited by javajynx; 08-24-2009 at 01:45 AM..
# 2  
Old 08-24-2009
Hi,

Here is your script with right commands and proper syntax.

Code:
>users
while true
do
  who | cut -d' ' -f1 |sort > 5secs
  diff -q users 5secs > /dev/null
  if [ $? -eq 0 ]
  then
     echo "No users have logged in/off in the past 5seconds"
  else
     comm -32 users 5secs|xargs -i echo {} has logged off
     comm -31 users 5secs|xargs -i echo {} has logged on
  fi
  mv 5secs users
  sleep 5
done


Regards,

Ranjith
# 3  
Old 08-24-2009
Thanks

Hey!
Thankyou for your help. It works great now
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Solaris 10 Login Page Loop

I'm currently logged in as Root on a Solaris 10 Server for my schools department and I'm trying to figure out why 20 of my users(Students) can log into the Solaris 10 Sun Ray Oracle Server with correct username and password but then be looped back to the same log in page. I tried deleting their... (7 Replies)
Discussion started by: mwilliams21z
7 Replies

2. UNIX for Advanced & Expert Users

Can adding to a new group be effective in current login environment without re-login?

Hey folks, When a user is added to a new group, the user has to be log out and log in again to make the new group effective. Is there any system command or technique to refresh user group ID update without re-login? I am not talking about to use "login" or "su -l" commands which can only make... (2 Replies)
Discussion started by: hce
2 Replies

3. Solaris

Solaris 10 Login Loop Problem

I recently installed Solaris 10 as a VM. I was using the JDS and shut down the vm when I left the office. When I rebooted today I login in at the desktop login screen and press ok but I am reverted to the console screen for a spilt second and then back to the login screen. I log in as root and my... (7 Replies)
Discussion started by: mvhoward
7 Replies

4. Shell Programming and Scripting

passing login details to htaccess login prompt

Hi, How i can pass the login details to the URL which is password protected with the htaccess using command line or script (perl,or shell,or php). Any help or hint appreciated. Thanks, SJ (4 Replies)
Discussion started by: SilvesterJ
4 Replies

5. AIX

User Account Login Login on your AIX server

I want to learn AIX. I would like to find someone who would be willing to give me a login to their AIX home lab server. My intent is to poke around and discover the similarities and differences of AIX compared to other *NIXs. I am a UNIX admin so I can think of what some immediate concerns may... (1 Reply)
Discussion started by: perl_in_my_shel
1 Replies

6. Solaris

error message rmclomv ... SC Login Failure for user Please login:

Hello World ~ HW : SUN Fire V240 OS : Solaris 8 Error message prompts 'rmclomv ... SC login failure ...' on terminal. and Error Message prompts continually 'SC Login Failure for user Please login:' on Single Mode(init S) The System is in normal operation, though In case of rain, Can... (1 Reply)
Discussion started by: lifegeek
1 Replies

7. Cybersecurity

APACHE: Tie in Web Page login with server login

Hello, I have created a web page on a server using apache and added .htaccess and .htpasswd in the folder for authentification. I was wondering if there was anyway to tie-in the login for this page with the login used to logon to the server. i.e. the same login info. is used for both, when... (1 Reply)
Discussion started by: WhotheWhat
1 Replies

8. Web Development

APACHE: Tie in Web Page login with server login

Hello, I have created a web page on a server using apache and added .htaccess and .htpasswd in the folder for authentification. I was wondering if there was anyway to tie-in the login for this page with the login used to logon to the server. i.e. the same login info. is used for both,... (2 Replies)
Discussion started by: WhotheWhat
2 Replies
Login or Register to Ask a Question