expect de scp (mzk-w04nu(or cqw-mr1000) + open wrt + motionで監視カメラComments 続き)
ここからのつづきです。
http://d.hatena.ne.jp/toshi_hirasawa/20120701/1341129079
夜中にリブートするようにする
# crontab -l 0 1 * * * reboot
http://d.hatena.ne.jp/toshi_hirasawa/20120701/1341129079
ここからの続き
http://d.hatena.ne.jp/toshi_hirasawa/20111018/1318889644
を参考に
#/etc/init.d/webcamの内容は
#!/bin/sh /etc/rc.common #/etc/init.d/webcam start() { if [ ! -e /mnt/sda1 ]; then mkdir /mnt/sda1 fi motion & } stop() { killall motion }
として、chmod + した後、chkconfigっぽいことをすればおけ
# cd /etc/rc.d/
# ln -s /etc/init.d/webcam S50webcam
sshで承認なしでrootログインできるようにしようとしたんだけど
なんだかうまくいかない orz
しょうがないないんでexpect
[root@cent5-64b-40 motion]# cat getfile #!/usr/bin/expect if {$argc != 1} { puts "Usage xxx (ex 192)" exit } set timeout 600 #set host_lastdig "xxx" set host_lastdig [lindex $argv 0] set host "192.168.1.${host_lastdig}" set passwd "xxxxxxxxxxxxx" set resp "root@pci-cqw" log_file expect.log spawn ssh root@${host} expect "root@${host}'s password:" send "${passwd}\n" expect "${resp}" send "ps -ef | grep motion\n" expect "${resp}" send "find /mnt/sda1 | wc -l\n" expect "${resp}" send "scp -pr /mnt/sda1/*jpg 192.168.1.40:/mnt/mnt2/motion/${host_lastdig}/\n" expect "root@192.168.1.40's password:" send "${passwd}\n" expect "${resp}" send "ps -ef | grep motion\n" expect "${resp}" send "exit\n" [root@cent5-64b-40 motion]#
scpでなくって、rsyncバージョン(でもやっぱりexpect orz)
バージョンはこちら
http://d.hatena.ne.jp/toshi_hirasawa/20130101/1357020124
/etc/motion.confに以下の部分を追加すれば、
イベントが発生した直後にコマンドをキックできるらしい(すばらしい)
on_event_end /root/on_event_end %v
そのうちためしてみよう、ということで以下作業用メモ
キックされるコマンド(on_event_end)はたとえば以下のような感じ
(
すいません以下URLからの完全にコピペです。オリジナル記事の方
http://homebrew.jp/show?page=1249
に感謝!)
#!/bin/ash #/root/on_event_end # current time date=`date` # search image files files=`ls /tmp/motion/$1-*` # temporary file name tmp=/tmp/tftp.motion.$$ # URLs for file urls="" # write tftp text on temporary file echo "mode octet" > $tmp for x in $files do fname=`echo $x | cut -d"/" -f4` echo put $x $fname >> $tmp urls="$urls\nhttp://homebrew.jp/share/motion/$fname" done echo quit >> $tmp # copy files to server cat $tmp | atftp 192.168.1.4 # send mail echo -e "Subject: Motion Event [$1]\n\n$date\nMotion event [$1] occured.\n$urls\n\n---\n" | ssmtp y.ogane@192.168.1.4 & # clean up rm $tmp rm $files echo "on_event_end: [$1] $date"