Simple check login script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple check login script
# 1  
Old 11-26-2012
Simple check login script

Hello,

I just started with shell and i am doin simple script to check if certain user is logged in. Script takes 3 args. name sleep time and quit value

if there is q for quit then date and user name is printed to file, not to screen.

so far i have got this...

Code:
login()
{	
	while :
	do
	if [[ `who | grep -c $name` -gt 0 ]]
	then
	echo "\a user $name is logged in"
	echo "User $name has logged in. `date`  >> logs.txt"
        sleep $freq
	else
	echo "User $name is not logged in"
	sleep $freq
	fi
	done
}

loginQ()
{
	while :
	do
	if [[ `who | grep -c $userName` -gt 0 ]]
	then
	echo "User $name has logged in. `date`  >> logs.txt"
        sleep $freq
	else
	sleep $freq
	fi
	done
}
	


if [ $# -le 3 -a $# -ge 1 ] 
then
name=$1
freq=$2
quit=$3

else

echo Invalid number of arguments
fi

if [ -z $frequency ]
then
frequency=60
fi

if [ $quit = q ]
then

loginQ()

else

login()

fi

Could someone help me with that if grep statement,as its not doing the work and is that if statment to check if freq is integer correct ?

Last edited by vbe; 11-26-2012 at 11:43 AM.. Reason: missing ] in red...
# 2  
Old 11-26-2012
In your 1rst test equal or less than 3 and equal or more than 1 leaves, with 1 or 2 or 3 args: so some could be not declared... worse: what happens if only arg3 is give? In your test it would be $1 I dont know what a quitvalue would do as a name...
(you had a missing ] also...)
# 3  
Old 11-26-2012
More I am looking at this script , the more I wonder if it is not homework...
# 4  
Old 11-26-2012
Please send me an PM to reopen this thread, the condition of course is you can assure us this is no school/homework! For homework you have to post in :
Homework & Coursework Questions - The UNIX and Linux Forums
Pay attention to the special rules there...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Simple Login script

Hi Guys Im new to bash script, trying hard to learn and enjoying this process. However i'm pretty much stumped, so i will put my problems out there. In the hope someone can help me. I am trying to make a bash script that allows users of a Unix system (with little knowledge under the hood ) to be... (12 Replies)
Discussion started by: willo
12 Replies

2. Shell Programming and Scripting

simple while loop script to check a connection

Hi, I am completely new to shell scripting. Basically I am wanting to create a simple while loop script to check if a network connection is available from 'netstat -a' and if its present then output a character to the serial port. I think i am nearly there.. but need some assistance.. this is... (9 Replies)
Discussion started by: zippyzip
9 Replies

3. Fedora

Simple login script in openSuSe

Hi guys, Ok so I'm basically trying to run a script on loging or after everything else has started up, I've done so much googling my head is spinning I don't understand the which file I have to edit with the details of my script, In suse there is no etc/profiles folder its daemonised so its... (1 Reply)
Discussion started by: whitenight639
1 Replies

4. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

5. Shell Programming and Scripting

Should be a simple subdirectory check

Ok. Just getting back into PERL and probably (or most definitely) making a mountain out of a mole hill. I'm trying to see if a subdirectory exists, and if not, print the slightly modified path of the missing sub to a file. Sounds simple enough. Well here is my elaborate code. Save the... (2 Replies)
Discussion started by: luvdairish
2 Replies

6. Web Development

Simple Login page

Hi all, I am stepping into web-development as a hobby point of view. I am using WAMP server & have created the initial page & SQL set-up too. My problem is, I was able to login to a page/redirect to a page though I haven't specified my username & password. I thought of using both... (2 Replies)
Discussion started by: gameboy87
2 Replies

7. Shell Programming and Scripting

Simple Script to Check running Process

#!/bin/sh CHECK='ps aux | grep start.jar | grep -v grep | wc -l' if then /usr/local/jre-1.7.0/bin/java - jar start.jar & else fi Could anybody advise whats up with this code im trying to put this in as a cron job to check that solr search engine is running every 10secs and if... (10 Replies)
Discussion started by: will_123
10 Replies

8. Programming

Using a script to check the login and username (html)

I made this named "confirm.sh":#/bin/sh #username and password are already given by the login form if ; then realpass=`cat /home/alex/Desktop/Myfirstsite/allpasses/$username` if ; then #continue with index.html else echo "Bad password" fi else echo "Unknown username" fi because I wanted... (4 Replies)
Discussion started by: hakermania
4 Replies

9. Shell Programming and Scripting

Script to calculate user's last login to check if > 90 days

I need a script to figure out if a user's last login was 90 days or older. OS=AIX 5.3, shell=Korn Here's what I have so far: ==== #!/usr/bin/ksh NOW=`lsuser -a time_last_login root | awk -F= '{ print $2 }'` (( LAST_LOGIN_TIME = 0 )) (( DIFF = $NOW - $LAST_LOGIN_TIME )) lsuser -a... (3 Replies)
Discussion started by: pdtak
3 Replies

10. UNIX for Dummies Questions & Answers

something simple, but i have no idea: a login issue

Hi all, I have a problem not really dramatic but realyl annoying: i've got a groups of users who logon a sunos 2.3 box via a windows telnet client (KEAI, but this is not the problem). they login as perso1 and password. It takes a very very very long time to get in. If i log on the same box... (2 Replies)
Discussion started by: penguin-friend
2 Replies
Login or Register to Ask a Question