'"WRITE" command works manually but not via script

My Co-Workers and I use the screen program on our Linux JUMP server to utilize as much screen space as possible. With that, we have multiple screens setup so that messages can go to one while we do work in another.

With that, i have a script that is used to verify network device connectivity which will send messages to my co-workers regardless if there is anything down or not.

The script initially references a file with their usernames in it and then grabs the highest PTS number which denotes the last screen session they activated and then puts it into the proper format in an external file like such:

  cat ./netops_techs | while read -r line; do
       temp=$(echo $line)
       temp2=$(who | grep $temp | sed 's/[^0-9]*//g' | sort -n -r | head -n1)

       if who | grep $temp; then
             echo "$temp pts/$temp2" >> ./tech_send
       fi
  done

Once it is done, it will then scan our network every 5 minutes and send updates to the folks in the file "./tech_send" like such:

Techs=$(cat ./tech_send)

if [ ! -f ./Failed.log  ]; then
        echo -e "\nNo network devices down at this time."
        for d in $Techs
        do
            cat ./no-down | write $d
        done
else
    # Writes downed buildings localy to my terminal
    echo -e "\nThe following devices are currently down:"
    echo ""
    echo "IP              Hostname        Model            Building  Room        Rack        Users Affected" > temp_down.log
    grep -f <(sed 's/.*/\^&\\>/' Failed.log) Asset-Location >> temp_down.log
    cat temp_down.log | column -t > Down.log
    cat Down.log
    
    # This will send the downed buildings to the rest of NetOps
    for d in $Techs
    do
        cat Down.log | write $d
    done 
fi

The issue stems from, when they are working in their main sectioned screen, the messages will pop up in that active screen instead of the inactive screen. If I send them a message manually such as:

write jsmith pts/25
Test Test

and then CTRL+D, it works fine even if they are in a different session. Via script though, it gives an error stating that:

write: jsmith is logged in more than once; writing to pts/23
write: jsmith/pts/25 is not logged in   

I have verified the "tech_send" file and it has the correct format for them:

jsmith pts/25

Would appreciate any insight on why this is happening.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source