Ben Stienstra

Linux, Unix, network, radio and more...

User Tools

Site Tools


full_packet_capture_system

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
full_packet_capture_system [2014/06/16 21:54]
admin
full_packet_capture_system [2014/06/17 10:48] (current)
admin
Line 137: Line 137:
  
 stop() { stop() {
- [ "$EUID" != "0" ] && exit 4+        [ "$EUID" != "0" ] && exit 4
         echo -n $"$prog, syncing RAM disk to NAS before shutdown."         echo -n $"$prog, syncing RAM disk to NAS before shutdown."
         echo " ---- STOP runlevel: `/sbin/runlevel` date:  `date`" >> /var/log/rsync.log         echo " ---- STOP runlevel: `/sbin/runlevel` date:  `date`" >> /var/log/rsync.log
         /usr/bin/rsync --quiet -a --log-file=/var/log/rsync.log $ramdisk/ $nas         /usr/bin/rsync --quiet -a --log-file=/var/log/rsync.log $ramdisk/ $nas
- RETVAL=$? +        RETVAL=$? 
- echo +        echo 
- [ $RETVAL -eq 0 ] && rm -f $lockfile +        [ $RETVAL -eq 0 ] && rm -f $lockfile 
- return $RETVAL+        return $RETVAL
 } }
  
 start() { start() {
- [ "$EUID" != "0" ] && exit 4+        [ "$EUID" != "0" ] && exit 4
         echo -n $"$prog, sync not needed at start-up."         echo -n $"$prog, sync not needed at start-up."
         echo " ---- START runlevel: `/sbin/runlevel` date: `date`" >> /var/log/rsync.log         echo " ---- START runlevel: `/sbin/runlevel` date: `date`" >> /var/log/rsync.log
- RETVAL=$? +        RETVAL=$? 
- echo +        echo 
- [ $RETVAL -eq 0 ] && touch $lockfile +        [ $RETVAL -eq 0 ] && touch $lockfile 
- return $RETVAL+        return $RETVAL
 } }
  
 sync() { sync() {
         [ "$EUID" != "0" ] && exit 4         [ "$EUID" != "0" ] && exit 4
-        # Sync all files but last (the one tcpdump is writing to)+        # Sync all files but last (the one tcpdump is writing to) to nas dir and year/day subdirs.
         # remove source files from RAM disk, if sync was succesful.         # remove source files from RAM disk, if sync was succesful.
-        ls $ramdisk | sort -t. -k2 | head -n -1 | /usr/bin/rsync --quiet -a --remove-source-files --log-file=/var/log/rsync.log --files-from=- $ramdisk/ $nas+ 
 +        # first create directory structure 
 +        mkdir -p $nas/`date +%Y/%m/%d` 
 +       
 +        # sync files 
 +        ls $ramdisk | sort -t. -k2 | head -n -1 | /usr/bin/rsync --quiet -a --remove-source-files --log-file=/var/log/rsync.log --files-from=- $ramdisk/ $nas/`date +%Y/%m/%d`
         RETVAL=$?         RETVAL=$?
         return $RETVAL         return $RETVAL
Line 168: Line 173:
 # See how we were called. # See how we were called.
 case "$1" in case "$1" in
-  stop) +  stop)  
- stop +        stop 
- ;;+        ;;
   start)   start)
- start +        start 
- ;; +        ;; 
-  sync) +  sync)  
- sync +        sync 
- ;;+        ;;
  
   *)   *)
- echo $"Usage: $0 {start|stop|sync}" +        echo $"Usage: $0 {start|stop|sync}" 
- exit 2 +        exit 2 
-esac</code>+esac 
 + 
 + 
 + 
 +</code>
 ===Enable rsync=== ===Enable rsync===
   * Run a cronjob to sync data to NAS every minute. Add to **/etc/crontab** <code>* *  *  *  * root service rsync-capture sync</code>   * Run a cronjob to sync data to NAS every minute. Add to **/etc/crontab** <code>* *  *  *  * root service rsync-capture sync</code>
full_packet_capture_system.txt · Last modified: 2014/06/17 10:48 by admin