Welcome to my site. Please CLICK HERE to give your opinions regarding this new look of "PCTipsbyAnu". Thanks for visiting.

Friday, October 8, 2010

Browse » Home » , , » How to make a script that will automatically notify specific user is logged in & loggedout?

How to make a script that will automatically notify specific user is logged in & loggedout?



Suppose that you are an Administrator (Computer Administrator) of your Company/School n you want to trace out a specific user when he/she logged-in or logged-out...
So, may be your prefrences is SOFTWAREs, but dude you can do same thing via a simple SCRIPT.


This script will automatically notify you when your specefied user is logger-in n logged-out.
Take a look...



1) LOG-IN SCRIPT

DOWNLOAD LINK

CODE:


#! /bin/sh
# #############################################################################

       NAME_="loggedin"
       HTML_="login alert"
    PURPOSE_="notify when a particular user has logged in"
   SYNOPSIS_="$NAME_ [-hml] "
   REQUIRES_="standard GNU commands"
     AUTHOR_="Admin:PCTipsbyANU "
        URL_="www.pctipsbyanu.tk"
      PLATFORM_="Linux"
      SHELL_="bash"


# #############################################################################


usage () {

echo >&2 "$NAME_ - $PURPOSE_
Usage: $SYNOPSIS_
Requires: $REQUIRES_
Options:
     , user name
     , integer referring to time in seconds for how often to check for the user
     -h, usage and options (this help)
     -m, manual
     -l, see this script"
    exit 1
}

manual () { echo >&2 "

NAME

    $NAME_ - $PURPOSE_

SYNOPSIS

    $SYNOPSIS_

DESCRIPTION

    $NAME_ displays a notification message when a particular user has logged in.
    The user option specifies the user name of the person and the time option is
    the time interval, in seconds, for how often to check whether the user has
    logged in.

AUTHOR

    $AUTHOR_ Suggestions and bug reports are welcome.
    For updates and more scripts visit $URL_

"; exit 1; }


loggedin() {

    # checking if user is logged out
    who | grep "^$1 " 2>&1 > /dev/null
    if [[ $? == 0 ]]; then
        echo user $1 is logged in
        exit 1
    fi

    # checking when user logs in
    until who | grep "^$1 "; do
        sleep $2
    done

    echo $1 just logged in
    exit 0
}

# arg check
[ $# -eq 0 ] && { echo >&2 missing argument, type $NAME_ -h for help; exit 1; }

case $1 in

    -h) usage;;
    -m) manual ;;
    -l) more $0; exit 1 ;;
     *) [ $# -eq 2 ] && loggedin $1 $2 || { echo >&2 invalid arg, type $NAME_ -h for help; exit 1; }

esac

2) LOG-OUT SCRIPT

DOWNLOAD LINK

CODE: 
 #! /bin/sh
# #############################################################################

       NAME_="loggedout"
       HTML_="logout alert script"
    PURPOSE_="notify when a particular user has logged out"
   SYNOPSIS_="$NAME_ [-hml] "
   REQUIRES_="standard GNU commands"
    AUTHOR_="Admin:PCTipsbyAnu "
        URL_="www.pctipsbyanu.tk"
   PLATFORM_="Linux"
      SHELL_="bash"
 
# #############################################################################

usage () {

echo >&2 "$NAME_ - $PURPOSE_
Usage: $SYNOPSIS_
Requires: $REQUIRES_
Options:
     , user name
     , integer referring to time in seconds for how often to check the user
     -h, usage and options (this help)
     -m, manual
     -l, see this script"
    exit 1
}

manual () { echo >&2 "

NAME

    $NAME_ - $PURPOSE_

SYNOPSIS

    $SYNOPSIS_

DESCRIPTION

    $NAME_ displays a notification message when a particular user has logged out.
    The user option specifies the user name of the person and the time option is
    the time interval, in seconds, for how often to check whether the user has
    logged out.

AUTHOR

    $AUTHOR_ Suggestions and bug reports are welcome.
    For updates and more scripts visit $URL_

"; exit 1; }


loggedout() {

    # checking if user is logged in
    who | grep "^$1 " 2>&1 > /dev/null
    if [[ $? != 0 ]]; then
        echo user $1 is not logged in
        exit 1
    fi

    # checking when user logs out
    while who | grep "^$1 "; do
        sleep $2
    done

    echo $1 just logged out
    exit 0
}

# arg check
[ $# -eq 0 ] && { echo >&2 missing argument, type $NAME_ -h for help; exit 1; }

case $1 in

    -h) usage ;;
    -m) manual ;;
    -l) more $0; exit 1 ;;
     *) [ $# -eq 2 ] && loggedout $1 $2 || { echo >&2 invalid arg, type $NAME_ -h for help; exit 1; }

esac
 If you got error from download file thn plz edit it n  $NAME_ $VERSION_ - $PURPOSE_remove the $VERSION_  from both files.

Thanks
You can leave a response, or trackback from your own site.

About 'Anu': My name is 'Anu' also Known as 'ANU 007 TIGER' .I'm administrator of 'PC Tips by Anu' blog .This blog was opened for sharing contents about hacking n cracking.
Thanks YAHOO OR GMAIL

0 comments:

Post a Comment

 
Back to Top