Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- VERSION=1.2
- PORT=514
- PRIORITY=14
- sendmsg() {
- echo "<$PRIORITY>$(date +'%b %e %T') $HOSTNAME $USER: $*" | nc -w 5 $SERVER $PORT 2> /dev/null
- }
- MSG=
- j=
- for i in $* ; do
- if [ "$j" == "-n" ] ; then
- SERVER=$i
- elif [ "$j" == "-P" ] ; then
- PORT=$i
- elif [ "$j" == "-p" ] ; then
- PRIORITY=$i
- elif [ "${i:0:1}" != "-" ] ; then
- if [ -z "$MSG" ] ; then
- MSG="$i"
- else
- MSG="$MSG $i"
- fi
- fi
- j=$i
- done
- if [ -z "$SERVER" ] ; then
- echo "BusyBox-friendly syslog sender v$VERSION"
- echo "Author: Branislav Vartik"
- echo
- echo "Usage: $0 -n <server> [-P <port>] [-p <priority>] [message]"
- echo
- echo "Defaults: message is read from STDIN"
- echo " port: 514 (only TCP due the BusyBox's NetCat limitations)"
- echo " priority: 14 (user.info)"
- else
- [ -z "$USER" ] && USER=$LOGNAME
- [ -z "$HOSTNAME" ] && HOSTNAME=$(grep -m 1 ^ /etc/hostname)
- if [ -z "$MSG" ] ; then
- # stdin which can be without last newline
- grep ^ | while read i ; do
- sendmsg "$i"
- done
- else
- sendmsg "$MSG"
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement