Demo entry 5862302

bb

   

Submitted by anonymous on Aug 02, 2016 at 19:43
Language: Bash. Code size: 1.6 kB.

 #!/bin/bash

splitsize=500
recipient="EMAIL@GMAIL.COM"
message="Thief entered your living room."
INBOX="/home/USER/CAMERAPROJECT/INBOX"
PROG="/home/USER/CAMERAPROJECT"
OUTBOX="/home/USER/CAMPERAPROJECT/OUTBOX"

echo "Target file path: $INBOX"
echo "Running zip_and_send.sh..." `date`
numfiles=$( ls -l $INB0X | egrep -c '^-')

numfolders=`expr $numfiles / $splitsize`
lastfoldercount=`expr $numfiles % $splitsize`

COUNTER=0
while [ $COUNTER -le $numfolders ]; do
 echo "Creating directory... " `date`
 DESTINATION="$INBOXCOUNTER"
 echo "Directory $DESTINATION created."
 sudo rm -rf $DESTINATION
 sudo mkdir -p $DESTINATION

 if [ "$COUNTER" -lt "$numfolders" ]; then
  for file in $(ls -p $INBOX | grep -v / | tail -$splitsize); do
   echo "File to be moved: $INBOX/$file to: $DESTINATION"
   sudo mv $INBOX/$file $DESTINATION
  done
 else
  for file in $(ls -p $INBOX | grep -v / | tail $lastfoldercount); do
   echo "File to be moved: $INBOX/$file to: $DESTINATION"
   sudo mv $INBOX/$file $DESTINATION
  done
 fi

 echo "Creating zip file... " `date`
 pushd $DESTINATION
 sudo zip -9 -r -q $OUTBOX/motion$COUNTER.zip $DESTINATION/*
 popd

 # sending email
 echo "Sending email to the recipient: $recipient" `date`
 echo $message | mutt -s "Catch the Thief!" $recipient -a $OUTBOX/motion$COUNTER.zip

 # cleaning the old files
 echo "Removing file: $OUTBOX/motion$COUNTER"
 sudo rm $OUTBOX/motion$COUNTER.zip
 sudo rm $DESTINATION/*
 sudo rmdir $DESTINATION
 echo "Removing $OUTBOX/motion$COUNTER"
 sudo rmdir $OUTBOX/motion$COUNTER

 let COUNTER=COUNTER+1
done

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).