stdinbot.sh 469 B

123456789101112131415161718192021222324
  1. #!/bin/sh
  2. if [ -z "$5" ]
  3. then
  4. printf '%s: Five arguments are required: Hostname, port, username, password and channel.\n' "$0" > /dev/stderr
  5. exit 1
  6. fi
  7. rm cow
  8. printf 'LOGIN\tUSERNAME=%s\tPASSWORD=%s\r\n' "$3" "$4" > cow
  9. (tail -n 1 -f cow | nc "$1" "$2") &
  10. ncid="$!"
  11. trap "kill $ncid" EXIT
  12. while read r
  13. do
  14. printf 'CHANMSG\tTARGET=%s\tMESSAGE=%s\r\n' "$5" "$r" >> cow
  15. done
  16. # this little part doesn't work because sigint isn't caught
  17. kill "$ncid"