[原创] 使用rpi + crontab + git 定时向bitbucket 推送 照片

#前提条件,你得有一个bitbucket的帐户

1.定时启动脚本代码

使用的是crontab 

 Cronfile 内容如下:

此文件的意思是,每隔10分钟,就运行一次 /home/pi/Rpi_upload.sh 脚本 

*/10 * * * * /home/pi/Rpi_upload.sh    

2. 添加到定时任务当中去

    

pi@raspberrypi$ crontab cronfile  #加载之前写的cronfile文件

查看有没有添加到定时任务 

  

pi@raspberrypi$ crontab -l 

显示内容如下:

*/10 * * * * /home/pi/Rpi_upload.sh 

3. 上传到 bitbucket的脚本如下:

# ! /bin/bash
#create by sndnvaps 
#date : 2015-03-30 
# bsd license 

random=$(date +%s%N)

jpegname=$random.jpg

#Takeshot use webcam
if [ ! -f $jpegname ];
      then

         echo $jpegname
         filename=$jpegname
         sudo fswebcam -d /dev/video1 -r 1280x720 --bottom-banner --title "RaspberryPi C270 @sndnvaps" /home/pi/$filename

      else
          echo "file $jpegname is exists!"
fi



#upload the pic to bitbucket.org

 if [  ! -d /opt/takeshot_rpi ]
        then
            mkdir -p /opt/takeshot_rpi
            cd /opt/takeshot_rpi
            git init
            git remote add origin git@bitbucket.org:sndnvaps/rpi_upload_pic.git
         else
            filename=$jpegname
            echo $filename
            sudo   cp /home/pi/$filename /opt/takeshot_rpi/
            cd /opt/takeshot_rpi
            git add *
            git commit -s -m "update $jpegname"
            git push origin master:master
            echo "upload $jpegname to bitbucket.org done."
 fi

 

posted @ 2015-03-30 19:29  sndnvaps  阅读(412)  评论(0编辑  收藏  举报