Share Pastebin
Guest
Public paste!

Gustavo Azambuja

By: a guest | Dec 10th, 2009 | Syntax: None | Size: 2.41 KB | Hits: 38 | Expires: Never
Copy text to clipboard
  1. #!/bin/bash
  2. ##
  3. ## Requisitos:
  4. ## sudo apt-get install fswebcam mailutils curl
  5. ##
  6. ## Script para tomar fotos de la webcam y subirlas por ftp
  7. ## Gustavo Azambuja - Linux User: 275813
  8. ## http://twitter.com/gazambuja
  9. ##
  10. ##
  11.  
  12. ## Elije el dispositivo (y el brillo asociado) por DEFecto y el ALTernativo:
  13. DEVICE_DEF="/dev/video1"
  14. DEVICE_ALT="/dev/video0"
  15. BRIGHT_DEF="10%"
  16. BRIGHT_ALT="50%"
  17.  
  18. ## Otros datos necesarios:
  19. EMAIL="miemail@gmail.com"
  20. FTPAUT="user:pass"
  21. FTPHOST="miftp.com.uy"
  22.  
  23. if [ -n $USERNAME ]; then
  24.         USERNAME=$USER
  25. fi
  26.  
  27. FUENTE="/usr/share/fonts/truetype/freefont/FreeSans.ttf"
  28. FECHA=`date +%d-%m-%Y`
  29. DIA=`date +%d`
  30. ANO=`date +%y`
  31. DAY5=`date --date='5 days ago' '+%d-%m-%Y'`
  32. AUTOSTART="/home/$USERNAME/.config/autostart/photos.desktop"
  33.  
  34. ##### Funciones #####
  35. function device {
  36.         if [ -c $DEVICE_DEF ]; then
  37.                 DEVICE=$DEVICE_DEF
  38.                 BRIGHT=$BRIGHT_DEF
  39.         else
  40.                 if [ -c $DEVICE_ALT ]; then
  41.                         DEVICE=$DEVICE_ALT
  42.                         BRIGHT=$BRIGHT_ALT
  43.                 else
  44.                         echo "Dispositivo no encontrado"
  45.                 fi
  46.         fi
  47. }
  48. function mailme {
  49.         SUBJECT="Fotos diarias para $USERNAME"
  50.         # Email text/message
  51.         EMAILMESSAGE="/tmp/emailmessage.txt"
  52.         echo "El script con las fotos esta funcionando, verificar en ftp://$FTPHOST/$USERNAME/ si los archivos estan correctos."> $EMAILMESSAGE
  53.         # send an email using /bin/mail
  54.         mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
  55.         rm /tmp/emailmessage.txt
  56. }
  57. function sacarfoto {
  58.         fswebcam --device $DEVICE --set brightness=$BRIGHT --resolution 640x480 --top-banner --skip 5 --title "$USERNAME en $HOSTNAME" --timestamp "%Y-%m-%d %H:%M (%Z)" --jpeg 95 --font $FUENTE --save /tmp/photo-$FECHA.jpg
  59.         curl -T /tmp/photo-$FECHA.jpg -u $FTPAUT ftp://$FTPHOST/$USERNAME/$ANO/$FECHA.jpg &> /tmp/photo-$FECHA.log
  60.         rm /tmp/photo-$DAY5.jpg
  61. }
  62.  
  63.  
  64.  
  65. ##### Main #####
  66.  
  67. ## Solo se ejecuta el script la primera vez que se hace login en cada dia:
  68. if [ ! -f /tmp/photo-$FECHA.jpg ]; then
  69.         device
  70.         sacarfoto
  71. fi
  72.  
  73. ## El 1 y el 15 de cada mes, enviamos un mail al usuario para que sepa que el script sigue funcionando:
  74. if [ $DIA = "01" ] || [ $DIA = "15" ]; then
  75.         mailme
  76. fi
  77.  
  78. ## Si no esta en el autorun del escritorio, creo el acceso directo:
  79. if [ ! -f $AUTOSTART ]; then
  80.         echo "[Desktop Entry]" > $AUTOSTART
  81.         echo "Name=Photos" >> $AUTOSTART
  82.         echo "Exec=/home/$USERNAME/.photos.sh" >> $AUTOSTART
  83.         echo "StartupNotify=false" >> $AUTOSTART
  84.         echo "Terminal=false" >> $AUTOSTART
  85.         echo "Type=Application" >> $AUTOSTART
  86. fi