- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- need a help with the shell script to trace which u...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2005 04:25 AM
04-23-2005 04:25 AM
need a help with the shell script to trace which user are logged on
i'm not good at shel programming and i need one script. This script schould chek who is logged on my system. If one user for exampel JEF logged on i should get immediately a messeg with informatin about this user ( username and time).
If user JEF exit my system i should get a another messega with the same information.
I should get only two message ( log on and log of)
I hoop i don't ask to much
Thank you in advance
IDriz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2005 05:39 AM
04-23-2005 05:39 AM
Re: need a help with the shell script to trace which user are logged on
who
put it in crontab for every 5 minutes and let the script check who's logged in, then you keep the current status and at the next check, compare the new status with the old and that way you can know what users logged in and who logged out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2005 08:17 AM
04-23-2005 08:17 AM
Re: need a help with the shell script to trace which user are logged on
I guess this is what you like:
#!/bin/sh
TMPFILE=/var/tmp/whocount
if [[ -f ${TMPFILE} ]]
then
oldcount=$(cat ${TMPFILE})
else
oldcount=0
fi
newcount=$(who|wc -l)
if (( ${oldcount} != ${newcount} ))
then
whoisthere=$(who)
mailx -m -s "Changing logins on UNIX can" you@domain.com << EOF
Hi,
These persons are logged in currently:
${whoisthere}
EOF
fi
echo ${newcount} > ${TMPFILE}
exit
Put above in a shell script and cron it.
Another possibility is to put this in a loop.
I hope this helped,
Renarios
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2005 08:41 AM
04-23-2005 08:41 AM
Re: need a help with the shell script to trace which user are logged on
I was not realy clear about what i want.
I should get a messege if only for exampele user JEF log on.
This user is an extern company who's helping as with one of our application.
I should know when they are connected to our system.
Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2005 08:57 AM
04-23-2005 08:57 AM
Re: need a help with the shell script to trace which user are logged on
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2005 09:29 AM
04-23-2005 09:29 AM
Re: need a help with the shell script to trace which user are logged on
Well try this then:
#!/bin/sh
TMPFILE=/var/tmp/whocount
if [[ -f ${TMPFILE} ]]
then
oldcount=$(cat ${TMPFILE})
else
oldcount=0
fi
newcount=$(who|wc -l)
if (( ${oldcount} != ${newcount} ))
then
whoisthere=$(who|grep JEF)
mailx -m -s "Changing logins on UNIX can" you@domain.com << EOF
Hi,
These persons are logged in currently:
${whoisthere}
EOF
fi
echo ${newcount} > ${TMPFILE}
exit
Put this in a cronjob every 1 minute or put it in a loop with a timeout.
Renarios
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2005 07:57 PM
04-23-2005 07:57 PM
Re: need a help with the shell script to trace which user are logged on
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2005 09:56 PM
04-23-2005 09:56 PM
Re: need a help with the shell script to trace which user are logged on
I agree with Alex, but the better place for this test is /etc/profile. You can add something like that:
USERS="JEF HJK POU"
for usr in $USERS; do
if [ $LOGNAME = $usr ]; then
date|mailx -s "$usr is loged in" yourmail
fi
done
Such a script permits you to controle more than one hacker
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2005 10:10 PM
04-23-2005 10:10 PM
Re: need a help with the shell script to trace which user are logged on
btw, hello Victor, I think we spoke over the phone last week, regarding the 11.09 version of Service Guard :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 04:38 AM
04-24-2005 04:38 AM
Re: need a help with the shell script to trace which user are logged on
I wil use both of them.
Victor kan you help me with this script of you. Do i have to put this code in the profile file (letterly) of somethings els.
Pleas help me because your solutions is somthing i'm looking for.
Another issue is log of (exit from the sessie). Kan i use the same script or i have to wait for the another solutioons?
Thank you in advance
Idriz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 04:44 AM
04-24-2005 04:44 AM
Re: need a help with the shell script to trace which user are logged on
i mean
Victor kan you help me with this script of you. Do i have to put this code in the profile file (literally) of somethings els.
Thank you
Idriz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 05:48 AM
04-24-2005 05:48 AM
Re: need a help with the shell script to trace which user are logged on
You can copy/paste the script into /etc/profile before the string with "trap" at the end of the file
Good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 06:11 AM
04-24-2005 06:11 AM
Re: need a help with the shell script to trace which user are logged on
Does it works with the logoff too ?
Idriz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 06:29 AM
04-24-2005 06:29 AM
Re: need a help with the shell script to trace which user are logged on
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 07:10 AM
04-24-2005 07:10 AM
Re: need a help with the shell script to trace which user are logged on
As far as I know. there is not a common file for logoff as /etc/profile for logon.
If you want to know about users' logoff, you will have to add into each user's .profile something like that:
trap 'echo $LOGNAME|mailx -s "$LOGNAME logged off" youremail' 0 1 2 3 15
Actually, I can't understand why you want to know about logoff. If you need to know such things, transfer your computer into trusted mode, you will have full logging.
HTH and good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 08:11 AM
04-24-2005 08:11 AM
Re: need a help with the shell script to trace which user are logged on
# cat .logout
# this line will add a line to the user's .sh_history
print -s "### logout at `/usr/bin/date` ###"
In .profile:
trap "$HOME/.logout" 0
You can also add the mailx in the .logout as well...
echo $LOGNAME|mailx -s "$LOGNAME logged off" youremail
Rgds...Geoff