difurious difurious - 3 months ago 10
Linux Question

Sending a warning message to certain users open terminals in tcl script

When running a section of my tcl script I would like to warn certain users with open terminals of what is happening. At the same time letting them know which terminal the message is being sent from. So far I have:

set who [exec who]
set user [lindex $who 0]
set who [split $who "\n"]

for { set i 0 } { $i < [llength $who] } { incr i } {
set current [lindex $who $i]
exec write $user [lindex $current 1]
# I would now like to send a message to this user
}


Except when I hit the "write" section the code gets stuck. As it can't exit. How do I pass tcl for shell variables to be written to desired user's terminal? Then exit the write section?

It does not look like i can use the "wall" command in linux.

Answer

You also need to supply an actual message to send. Assuming you are sending the same message to each, just put the message in a variable at the top of your script and use a heredoc with exec to supply it as write's standard input.

set who [exec who]
set user [lindex $who 0]
set who [split $who "\n"]
set message "The quick brown fox is jumping over the lazy dog.\n"

for { set i 0 } { $i < [llength $who] } { incr i } {
    set current [lindex $who $i]
    exec write $user [lindex $current 1] << $message
}
Comments