Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to log inactive users 1

Status
Not open for further replies.
Oct 2, 2002
2
US
I am trying to find or write a script that will log users who have been inactive for more than a set amount of time to a file.

Thanks
 
You can use expect which makes it simple..or some
kludge which is not as simple.

#!/usr/bin/expect
spawn -noecho /bin/sh
set time 100
interact {
timeout $time {
log_file "User $env(UID) has been idle for $time."
}

-o
timeout $time {
log_file "User $env(UID) has been idle for $time."
}
}
 
When I run the above script I get the following...

# can't read "env(UID)": no such variable
while executing
"log_file "User $env(UID) has been idle for $time.""
invoked from within
"interact -nobrace timeout 100 {
log_file "User $env(UID) has been idle for $time."
} -o timeout 100 {
log_file "User $env(UID) has been id..."
invoked from within
"interact {
timeout $time {
log_file "User $env(UID) has been idle for $time."
}

-o
timeout $time {
log_file "User $env(UID) h..."
(file "./log.sc" line 4)


I know next to nothing about unix scripting, so how do I find the appropriate user id environment variable for my system? I'm running HP-UX 11.0.

Thanks
 
#!/bin/sh

who | awk '{ split($5,idleTime, ":")
if (idleTime[2] >= 30)
printf("%s %s has been idle
for 30 minutes", $1, $3)
}' > idlers_file.$$
# to send message to their terminsl,do the following...

cat idlers_file.$$ | while read line
do
idlers=`awk '{print $1}'`
terminal=`awk '{print $3}'`

write $idler $terminal < idle_message.txt
done

This is very generic but is a start. I'm not sure that the field numbers from the who command are correct. I used $5 for the idle time and $3 for the terminal. May be different. (I'm not at a terminal).Might need to evaluate those fields for better accuracy. Hope this helps for what it's worth :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top