aboutsummaryrefslogtreecommitdiff
path: root/clients/shellclients/stdinclient-vitali64.sh
blob: 4ce2b8544ff886ac42fbb9269931506f39cc36dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh

if [ -z "$5" ]
then
    printf '%s: Five arguments are required: Hostname, port, username, password and channel.\n' "$0" > /dev/stderr
    exit 1
fi

rm cow
printf 'LOGIN\tUSERNAME=%s\tPASSWORD=%s\r\n' "$3" "$4" > cow

tail -n 1 -f cow | nc "$1" "$2" | sed -e "s/CHANMSG\tSOURCE=/"$(date '+%H:%M')" </g" -e 's/\tMESSAGE=/> /g' -e "s/\tTARGET=$5//g" -e 's/\tTYPE=NORMAL//g' &
ncid="$!" 

trap "kill $ncid" EXIT

while read r
    do
	date=$(date +%H:%M)
    printf 'CHANMSG\tTARGET=%s\tMESSAGE=%s\r\n' "$5" "$r" >> cow
	done

# this little part doesn't work because sigint isn't caught
kill "$ncid"