sendaljepits

Install Motion dan kirim file jpg ke email

Jan 1st, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. PART 1 INSTALL MOTION DULU
  2. ################################################
  3. 1.opkg install motion
  4. nano /etc/default/motion
  5. 2.start_motion_daemon=yes
  6. 3.nano /etc/motion/motion.conf
  7. daemon
  8. set to on
  9. width
  10. set to 320
  11. height
  12. set to 240
  13. webcam_localhost
  14. set to off
  15. webcam_port
  16. set to 8291 # terserah port berapa
  17. target_dir
  18. change to target_dir /data/webcam/motion
  19. 4.chmod 664 /etc/motion.conf
  20. 5.chmod 755 /usr/bin/motion
  21. 6.touch /var/log/motion.log
  22. 7.chmod 777 /var/log/motion.log
  23. 8.nano /bin/startmotion.sh
  24. LOG=/var/log/motion.log
  25. echo "Start Motion Script" `date` >> /var/log/motion.log
  26. /usr/bin/motion 2>&1 | tee -a $LOG &
  27. ctrl + x yes
  28. 9.nano /bin/stopmotion.sh
  29. #!/bin/bash
  30. LOG=/var/log/motion.log
  31. # Script details
  32. echo "Stop Motion Script" `date` >> /var/log/motion.log
  33. pkill motion 2>&1 | tee -a $LOG
  34. ctrl + x yes
  35. 10.chmod u+x /bin/startmotion.sh
  36. 11.chmod 755 /bin/startmotion.sh
  37. 12.chmod u+x /bin/stopmotion.sh
  38. 13.chmod 755 /bin/stopmotion.sh
  39. startmotion.sh >>>>>>>>> untuk menjalankan motion
  40. stopmotion.sh >>>>>>>>> untuk stop motion
  41. ###############################################################################
  42. PART 2 INSTALL PAKET EMAIL
  43. 1.opkg install ssmtp
  44. 2.nano /etc/ssmtp/ssmtp.conf
  45. #root=your_username@yahoo.com # Uncomment this line and comment the following if using yahoo
  46. root=isi email_juragan@gmail.com
  47. #mailhub=smtp.mail.yahoo.com:587 # Uncomment this line and comment the following if using yahoo
  48. mailhub=smtp.gmail.com:587
  49. #rewriteDomain=yahoo.com # Uncomment this line and comment the following if using yahoo
  50. rewriteDomain=gmail.com
  51. #hostname=your_username@yahoo.com # Uncomment this line and comment the following if using yahoo
  52. hostname=root
  53. # Use SSL/TLS before starting negotiation
  54. #UseTLS=Yes
  55. UseSTARTTLS=Yes
  56. # Username/Password
  57. AuthUser=email_juragan@gmail.com # <<< isi email juragan
  58. AuthPass=password_juragan # <<< isi password juragan
  59. # Email 'From header's can override the default domain?
  60. FromLineOverride=yes
  61. 3.chmod 774 /etc/ssmtp/ssmtp.conf
  62. 4.chown root:mail /etc/ssmtp/ssmtp.conf
  63. 5.nano /etc/ssmtp/revaliases
  64. #root:your_username@yahoo.com:smtp.mail.yahoo.com:587 # Uncomment this line and comment the following if using yahoo
  65. root:email_juragan@gmail.com:smtp.gmail.com:587
  66. 6.opkg install zip
  67. 7.opkg install mutt
  68. 8.mkdir -p ~/.mutt/cache/{headers,bodies}
  69. 9.mkdir ~/.mutt/certificates
  70. 10.nano ~/.muttrc
  71. set sendmail="/usr/sbin/ssmtp"
  72. # replace with your email address, should be the same address as what you've us$
  73. set from="email_juragan@gmail.com"
  74. set use_from=yes
  75. #end-----------------------------------------
  76. 11.nano /bin/zipandmail.sh
  77. #!/bin/bash
  78. #Yahoo and Gmail only allow attachment size of 25MB.
  79. #For example, 800x608 @ 50% motion detection jpegs, each file is 33~43KB.
  80. #Each folder should about 500 files so as not to exceed 20MB when zipped.
  81. #Change the default 500 to a smaller value if your recipient's email provider's$
  82. #splitsize=250
  83. splitsize=50
  84. #Email recipient(s), separated by space
  85. recipient="email_juragan@gmail.com" # isi email juragan.klo mau kirim ke satu email
  86. #recipient="foo@gmail.com foo@yahoo.com" # kalo mau kirim ke 2 email
  87. #Email subject and message
  88. message="Isi mail"
  89. #Motion target files path
  90. targetfilepath="/data/webcam/motion"
  91. #Motion target directory path
  92. targetdirpath="/data/webcam"
  93. ####################################
  94. echo "Menjalankan zipandmail.sh..." `date`
  95. #count number of files in motion directory
  96. numfiles=$( ls -l $targetfilepath | egrep -c '^-')
  97. numfolders=`expr $numfiles / $splitsize`
  98. lastfoldercount=`expr $numfiles % $splitsize`
  99. echo $numfiles
  100. #echo $numfolders
  101. #echo $lastfoldercount
  102. #Move all files from motion directory to newly created directories based on $nu$
  103. COUNTER=0
  104. while [ $COUNTER -le $numfolders ]; do
  105. echo "Mencari directory... " `date`
  106. destination="$targetfilepath$COUNTER"
  107. rm -rf $destination
  108. mkdir -p $destination
  109. #move multiples of $splitsize files to new folder(s) except the remainder files$
  110. if [ "$COUNTER" -lt "$numfolders" ]; then
  111. for file in $(ls -p $targetfilepath | grep -v / | tail -$splitsize); do
  112. mv $targetfilepath/$file $destination
  113. done
  114. #move remainder files in last new motion folder
  115. else
  116. for file in $(ls -p $targetfilepath | grep -v / | tail -$lastfoldercount); $
  117. mv $targetfilepath/$file $destination
  118. done
  119. fi
  120. echo "Membuat zip file... " `date`
  121. pushd $targetdirpath
  122. zip -9 -r -q motion$COUNTER.zip ./motion$COUNTER/
  123. popd
  124. echo "Mengirim mail ke penerima... " `date`
  125. echo $message | mutt -s "subject of the email" $recipient -a $targetfilepath$$
  126. let COUNTER=COUNTER+1
  127. done
  128. 12.zipandmail.sh <<<<< untuk menjalankan perintah zip file jpg,trus kirim ke email juragan
Add Comment
Please, Sign In to add comment