Sponsored Content
Full Discussion: Simple check login script
Top Forums Shell Programming and Scripting Simple check login script Post 302735859 by shelllo on Monday 26th of November 2012 09:52:56 AM
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...
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

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

8. 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

9. 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

10. 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
SLEEPENH(1)						      General Commands Manual						       SLEEPENH(1)

NAME
sleepenh - an enhanced sleep program. SYNOPSIS
sleepenh [initial-time] sleep-time DESCRIPTION
sleepenh is a program that can be used when there is a need to execute some functions periodically in a shell script. It was not designed to be accurate for a single sleep, but to be accurate in a sequence of consecutive sleeps. After a successful execution, it returns to stdout the timestamp it finished running, that can be used as initial-time to a successive exe- cution of sleepenh. OPTIONS
There are no command line options. Run it without any option to get a brief help and version. ARGUMENTS
sleep-time is a real number in seconds, with microseconds resolution (1 minute, 20 seconds and 123456 microseconds would be 80.123456). initial-time is a real number in seconds, with microseconds resolution. This number is system dependent. In GNU/Linux systems, it is the number of seconds since midnight 1970-01-01 GMT. Do not try to get a good value of initial-time. Use the value supplied by a previous exe- cution of sleepenh. If you don't specify initial-time, it is assumed the current-time. EXIT STATUS
An exit status greater or equal to 10 means failure. Known exit status: 0 Success. 1 Success. There was no need to sleep. (means that initial-time + sleep-time was greater than current-time). 10 Failure. Missing command line arguments. 11 Failure. Did not receive SIGALRM. 12 Failure. Argument is not a number. 13 Failure. System error, could not get current time. USAGE EXAMPLE
Suppose you need to send the char 'A' to the serial port ttyS0 every 4 seconds. This will do that: #!/bin/sh TIMESTAMP=`sleepenh 0` while true; do # send the byte to ttyS0 echo -n "A" > /dev/ttyS0; # just print a nice message on screen echo -n "I sent 'A' to ttyS0, time now is "; sleepenh 0; # wait the required time TIMESTAMP=`sleepenh $TIMESTAMP 4.0`; done HINT
This program can be used to get the current time. Just execute: sleepenh 0 BUGS
It is not accurate for a single sleep. Short sleep-times will also not be accurate. SEE ALSO
date(1), sleep(1). AUTHOR
This manual page was written by Pedro Zorzenon Neto. 2008/04/20 SLEEPENH(1)
All times are GMT -4. The time now is 03:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy