Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- collectCrashReport() {
- # teleport to cache dir
- cd /mnt/cache
- # remove any previous report
- rm -rf crash/crashreport_*
- # create report directory
- directory=crashreport_`cat /etc/hostname`_$(date +%Y%m%d%H%M%S)
- mkdir $directory
- cd $directory
- # snatch all the logs
- cp -r /var/log/ .
- ps --no-headers -ax > processes.dump
- # dump dmesg to file
- dmesg > dmesg.dump
- # create crash dir
- mkdir crash
- # zip the whole thing
- zip -qr /mnt/cache/crash/"$directory.zip" .
- # remove collection dir
- rm -rf /mnt/cache/crashreport_*
- # done and done
- }
- # check if already running and kill
- PIDFILE=/var/run/crashcollector.pid
- # check if already running
- if [ -f $PIDFILE ]; then
- kill `cat $PIDFILE`
- fi
- echo $$ > $PIDFILE
- cleanup() {
- rm -f $PIDFILE
- exit 0
- }
- # trap them signals
- trap "cleanup" INT TERM EXIT
- that_awesome_pipe="CCPipe"
- [ -p $that_awesome_pipe ] || mkfifo $that_awesome_pipe
- chmod 766 $that_awesome_pipe
- while :; do
- if read line; then
- case $line in
- "collect")
- collectCrashReport
- ;;
- *)
- log "Received bad command $line, ignoring..."
- ;;
- esac
- fi
- done <"$that_awesome_pipe"
- [Unit]
- Description=Crash report collector
- After=network.target
- [Service]
- Type=simple
- ExecStart=/usr/bin/crashCollector
- ExecStop=/usr/bin/kill -9 `cat /var/run/crashcollector.pid`
- KillMode=process
- Restart=always
- RestartSec=3
- [Install]
- WantedBy=multi-user.target
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement