Created
February 16, 2016 17:54
-
-
Save irvifa/1b7eaba79c914d03b27e to your computer and use it in GitHub Desktop.
misc-bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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