Skip to content

Instantly share code, notes, and snippets.

@pozgo
Last active October 8, 2015 20:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pozgo/e38acdf3d194ce1c8c4b to your computer and use it in GitHub Desktop.
Save pozgo/e38acdf3d194ce1c8c4b to your computer and use it in GitHub Desktop.
Journalctl to file for logstash-forwarder process
#!/bin/bash
is=`ps aux | grep "journalctl -f" | grep -v grep | awk '{print$2}'`
file=/var/log/system.log
msize="12400000" # Max file sieze set to 10MB
asize=`ls -l /var/log/system.log | awk '{print$5}'`
logstaship=`fleetctl list-machines -l | grep logsystem | awk '{print$2}'`
hostname=`hostname`
# Checking the size of log file
if [ $asize -gt $msize ]
then
echo "" > $file
fi
#Start Journal Dump if not working
if [ -z "$is" ]
then
sudo journalctl -f -a >> $file &
sudo docker run -d --name logforwarder -h $hostname --env LOGSTASH_IP=$logstaship -v /var/log:/data/log million12/logstash-forwarder
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment