- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script help
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
09-25-2003 07:11 AM
09-25-2003 07:11 AM
I have two scripts currently that I use to try and tell me who has been idle for greater than 1 hour > which writes the users out to a file.txt.
Then the second script looks at this file.txt and does a grep to see if it is still connected to a db, Progress (_prog). If they are, then write out to a newfile.txt.
My questions are this: Can I combine the two, hopefully, so that the system can generate and send the user an email asking them to logoff when idle.
Secondly, my second script appears to be catching users that do NOT meet the grep syntax.
Suggestion/help appreciated.
script one to check for idle users > 1 hour
#!/usr/bin/ksh
HOST=$(hostname)
EVERY=1
MESSAGE="please consider logging out"
#SUBJECT="You are IDLE on $HOST"
rm /home1/nickd/scripts/idleusers.txt
get_user()
{
USER=$(echo $LINE|awk '{print $1}')
IDLE=$(echo $LINE|awk '{print $6}')
if [ "$IDLE" = "old" ]
then
echo $MESSAGE |mailx -s $SUBJECT $USER
#write $USER > /home1/nickd/scripts/idleusers.txt
else
IDLE_HOURS=$(echo $IDLE|awk '{FS=":";print $1}')
if [ "$IDLE_HOURS" -ge 1 ]
then
echo $USER >> /home1/nickd/scripts/idleusers.txt
#echo $MESSAGE |mailx -s $SUBJECT $USER
fi
fi
}
who -u|while read LINE
do
get_user $LINE
done
Script 2 to see if they are still connected to db:
!/bin/sh
rm /home1/nickd/scripts/testuser.txt
for i in $(cat /home1/nickd/scripts/idleusers.txt)
do
#cat /home1/nickd/scripts/idleusers.txt |grep _pro |tee -a foundPatterns.txt
#ps -ef | grep $i | grep _prog | grep notrim > /home1/nickd/scripts/dbidle.txt
ps -ef | grep $i | grep notrim > /home1/nickd/scripts/dbidle.txt
print $i >> /home1/nickd/scripts/testuser.txt
done
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2003 07:24 AM
09-25-2003 07:24 AM
Re: script help
In your second script, you make no differentiation between the two.
I think in script 1 that you need to copy the tty/pty combo into the idle users file and check those in the grep of the ps -ef instead of the user name.
Best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2003 07:26 AM
09-25-2003 07:26 AM
Re: script help
Not exactly the answer to your question, but you can add a line like:
TMOUT=600
to the users .profile (or /etc/profile for all users).
THis will log users out after 10 minutes of idle time.
Of course they can always change their .profile and remove it.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2003 07:26 AM
09-25-2003 07:26 AM
Re: script help
I don't know why.
Here is how to fix it.
Change grep to:
... | grep -i stuff
... | grep -i stuff | grep -v grep
This sometimes helps clean up the output.
I'm attaching a script purely because it contains expamples. It will not help with your script except as a reference.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2003 07:27 AM
09-25-2003 07:27 AM
Re: script help
Also another problem, is the printing out to the testuser.txt file only writes out one user instead of the 3 or 4 that are in violation of this one hour rule.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2003 07:32 AM
09-25-2003 07:32 AM
Re: script help
David, A timeout setting at the OS before the connection is closed on the DB side, can be dangerous for data corruption.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2003 07:40 AM
09-25-2003 07:40 AM
Re: script help
- Raw "who -u" output
- Copy of the idleusers.txt output file from the script run immeadiately after the who -u
- Copy of the testuser.txt file immeadiatetly after 2nd script was run.
My brain works better when I can analyze the data right in front of me.
Best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2003 07:44 AM
09-25-2003 07:44 AM
Re: script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2003 08:07 AM
09-25-2003 08:07 AM
Re: script help
export TMOUT=1800
to /etc/profile
and this will give a user short notification
and log him out after 30 mins of idling.
It will not to try log off user if user have running editor (vi) or another interactive utility (sqlplus).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2003 08:15 AM
09-25-2003 08:15 AM
Re: script help
You will need to modify the path names to match what you want, but this should work.
First create a file called "useme.awk" which should contain:
{index1=index($2,"tty");
if (index1==0)
use2=$2
else
use2=substr($2,index1);
print "ps -ef| grep _prog | grep " use2 "| grep -v grep" ;}
NOTE: That print statement should be all one line.
Then create a script file:
#!/usr/bin/ksh
touch useme1 useme2 useme3
rm useme1 useme2 useme3
who -u | grep old | cut -c1-24 > useme1
awk -f useme.awk < useme1 > useme2
chmod +x useme2
./useme2 > useme3
cat useme3 | while read LINE
do
USER=$(echo $LINE|awk '{print $1}')
mailx -s "You have been logged in too long" $USER < messagefile
done
Also note, the script uses three temporary files useme1, useme2, and useme3.
And the script will mail a message called "messagefile" to the user.
The logic is to find old logins with
who -u | grep old
Then match the tty or pty to the ps output.
Then email those users who matched.
Hope that helps.
Best regards,
Kent M. Ostby
Once you've got a match
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2003 08:17 AM
09-25-2003 08:17 AM
Re: script help
[RE-POST in what is hopefully a more readable format ]
Okay .. I think I have something working.
You will need to modify the path names to match what you want, but this should work.
First create a file called "useme.awk" which should contain:
{index1=index($2,"tty");
if (index1==0)
use2=$2
else
use2=substr($2,index1);
print "ps -ef| grep _prog | grep " use2 "| grep -v grep" ;}
NOTE: That print statement should be all one line.
Then create a script file:
#!/usr/bin/ksh
touch useme1 useme2 useme3
rm useme1 useme2 useme3
who -u | grep old | cut -c1-24 > useme1
awk -f useme.awk < useme1 > useme2
chmod +x useme2
./useme2 > useme3
cat useme3 | while read LINE
do
USER=$(echo $LINE|awk '{print $1}')
mailx -s "You have been logged in too long" $USER < messagefile
done
Also note, the script uses three temporary files useme1, useme2, and useme3.
And the script will mail a message called "messagefile" to the user so you need to create that.
The logic is to find old logins with
who -u | grep old
Then match the tty or pty to the ps output.
Then email those users who matched.
Hope that helps.
Best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2003 12:38 AM
09-29-2003 12:38 AM
Re: script help
Very good, however, it appears that the script is only looking for the word old, and I need everything greater than 1.00 in that field.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2003 01:40 AM
09-29-2003 01:40 AM
Re: script help
tcp_keepalive_interval.
This will timeout any connection that exceeds the keepalive interval. This is normally 2 hours, which is a little long to keep an invalid session hanging around.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2003 01:42 AM
09-29-2003 01:42 AM
Re: script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2003 01:52 AM
09-29-2003 01:52 AM
Solutionif I understand this correctly, you could try and change this line in Kent's script:
who -u | grep old | cut -c1-24 > useme1
to:
who -u|awk ' $6 ~ /[1-9]:[0-9][0-9]/ {print $1,$2}' > useme1
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2003 02:02 AM
09-29-2003 02:02 AM
Re: script help
I modified the script so that it captures the user to a tmp file also so that I can keep track of consistantly deliquent users.
Sorry Kent, I should have assigned you the points, please post one more time and I will assign points to you once more.
Thank You,