1846135 Members
4938 Online
110254 Solutions
New Discussion

Re: Shell Script needed

 
HT Li
New Member

Shell Script needed

Hi:
I need to get a UNIX shell script to "wall" to users individually every # of minutes after they logged in. Different users might login to UNIX at various times and they need to be "walled" only after # minutes after they logged in. I tried using last, w, and read
links in this forum but did not find any such scripts.
Thanks in advance.
HT
11 REPLIES 11
Fragon
Trusted Contributor

Re: Shell Script needed

Hi,
I think it's difficult but there are always some ways...mmmmmm, now I get a new one even it is a little folly:
You can put the wall file to somedir, for example /tmp/wallmsg.txt.
In users' .profile, edit their cron(repeat) or at(once) schedule to "ECHO"(more or cat) /tmp/wallmsg.txt every # of minutes.
You can make each ".profile" 555 if you want!
For this way, wall is not needed!

Others?
:p

-ux
Donny Jekels
Respected Contributor

Re: Shell Script needed

Li,

sounds like a cool project.

did you know in korn shell there is a timeout variable you can set per user. this will time out idle users after preset time.

although the top has nothing to do with your request, here is my guideline as to how you should approach this project/script/daemon

1. the script must run as a daemon in order to work properly.

2. you must then build a timer inside the daemon to check for logged in users at a specific time or at every XX seconds.

3. once it reach that time, wall each of the users at their terminals whatevr you want,

4. finally go to sleep again for xx time.

5. repeat the process
"Vision, is the art of seeing the invisible"
Michael Steele_2
Honored Contributor

Re: Shell Script needed

Use 'finger -q' to obtain 'login time'. Parse it through awk to separate the 'login time' data field. Use this integer value for your test determination: "...every # of minutes after they log in...".

Use cron at 5 minute intervals to launch the script. DON'T USE sleep IN A .profile file. This will fill up your process table.

http://docs.hp.com/cgi-bin/fsearch/framedisplay?top=/hpux/onlinedocs/B9106-90007/B9106-90007_top.html&con=/hpux/onlinedocs/B9106-90007/00/01/105-con.html&toc=/hpux/onlinedocs/B9106-90007/00/01/105-toc.html&searchterms=finger&queryid=20030624-205156
Support Fatherhood - Stop Family Law
Donny Jekels
Respected Contributor

Re: Shell Script needed

sorry, well its not my fault the forum server locks up.

anyway let start.

# we are going to use functions

mytime=$(date +%H%M%S)
# debug
echo ${mytime}

check_users(){

users=$(who -um | awk '{print $1}'
#this will record all the currenly logged in users to the variable $users

}

wall_em() {

check_users

if [ -n $users ]
then
# well, we have users - whoooo hoooo!!
# wall or banner them
wall $users
else
# hey gues what - there is no users logged in - peace on earth
:
fi
}


# now lets start the process

while true
do # daemon loop
wall_em
# when youre done
# then wait for a few seconds
sleep 900 # you don't want to piss off your users - so 15 minutes is good.
done

exit 0


# hey its that easy- let me know


liev free or die
donny
"Vision, is the art of seeing the invisible"
Kenneth_19
Trusted Contributor

Re: Shell Script needed

While I guess the difficulty is that "wall" is unconditional, well, you can only "wall" to all or particular group of users, but not users or terminals remains logon for certain minutes of time.

How about setup a cron job in root, and get the connected user/terminal list with the "who" command, and calculate the time difference between system time and logon time, those who satisfy the conditional of logging in for more than # minutes will be written a message to their terminals one by one with:

# echo your message > /dev/tty/ta

I have a c program to calculate the difference between two date-time, see attached file.
Always take care of your dearest before it is too late
Donny Jekels
Respected Contributor

Re: Shell Script needed

the above script will cover all your users logged in at once.

if you want to do it on a per user basis. then you have to record the time they logged in.

then don't do it in their .profile - many users will delete the code.

this gets a little tricy not impossible.

let me think about it for a while - i'll get back to you.

"Vision, is the art of seeing the invisible"
HT Li
New Member

Re: Shell Script needed

Thanks for the replies. Ken raised a good point. Michael and Donny's proposals are better so far. Sorry I was not clear enough, "wall" should really be "send message" to users individually. Note that I can't use .profile solution. I need a daemon type of solution. Thanks again.
HT Li
New Member

Re: Shell Script needed

I used Ken's C program and got it to work using the following parameters:
a.out `date "+%Y %m %d %H %M %S"` `date "+%Y %m %d %H %M %S"`

who or finger -q returns in the format
Jun 26 06:39 how to convert it to
"2003 06 26 06 39 ss"
Thanks.
harry d brown jr
Honored Contributor

Re: Shell Script needed

man write

note, the process will have to be a root process. I really think this should be done via the application and not a daemon. There's nothing like screwing up a users screen with messages, especially if the application doesn't have a REDRAW feature.

live free or die
harry
Live Free or Die
Kenneth_19
Trusted Contributor

Re: Shell Script needed

In that case you need to build some logic in your scripts to convert the month from mmm to mm:

case $MMM in
"Jan")
MM=1
;;
"Feb")
MM=2
;;

:
:
"Dec")
MM=12
;;
esac
Always take care of your dearest before it is too late
rachel_11
Advisor

Re: Shell Script needed

Hello,

There is a simple solution, can be applied from login startup script.

craete a script that contains:
write $LOGNAME << EOT
Your notification
EOT

At startup script enter the command
at now + # minutes script