Skip to content

Instantly share code, notes, and snippets.

@irvifa
Created February 16, 2016 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irvifa/1b7eaba79c914d03b27e to your computer and use it in GitHub Desktop.
Save irvifa/1b7eaba79c914d03b27e to your computer and use it in GitHub Desktop.
misc-bash
#!/bin/bash
LOG_DIR=/var/log
ROOT_UID=0
LINES=50
E_XCD=86
E_NOTROOT=87
MESSAGES=messages
TMP=mesg.tmp
if [ "$UID" -ne "$ROOT_UID" ]; then
echo "Must be root."
exit $E_NOTROOT
fi
if [ -n "$!" ]; then
lines=$1
else
lines=$LINES
fi
cd $LOG_DIR
if [ `pwd` != "$LOG_DIR" ]; then
echo "Can't change to $LOG_DIR."
exit $E_XCD
fi
tail -n $lines $MESSAGES > TMP
mv $TMP $MESSAGES
cat /dev/null > wtmp
echo "Log files cleaned up."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment