BASH   70

webcam bash

Guest on 21st April 2022 01:29:54 AM

  1. #!/bin/bash
  2.  
  3. # script for using your linux laptops camera as webcam
  4. # for upload to work, you must add your public SSH key to PUBLISHING_HOSTs ~/.ssh/authorized_keys
  5. # dependencies: ssh scp fswebcam
  6.  
  7. # conf
  8.  
  9. INTERVAL_IN_SECONDS=30
  10. PUBLISHING_HOST=localhost@localhost
  11. PUBLISHING_DIR=/home/juks/public_html/cam
  12.  
  13. # constants
  14.  
  15. IMG0=index.jpg
  16. IMG1=new.jpg
  17. INDEX=index.html
  18. TXT_NEXT="Interval of photos: "$INTERVAL_IN_SECONDS" seconds."
  19.  
  20. # generate and upload main page
  21.  
  22. cat <<EOF > $INDEX
  23. <html>
  24. <head>
  25. <title>Cam</title>
  26. <meta http-equiv=Content-Type content="text/html; charset=UTF-8">
  27. <meta http-equiv="Refresh" content="$INTERVAL_IN_SECONDS">
  28. <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate, max-age=0"/>
  29. <meta http-equiv="Pragma" content="no-cache"/>
  30. <meta http-equiv="Expires" content="0"/>
  31. <style>
  32. html, body {
  33.     background-color: black;
  34.     height: 100%;
  35.     margin: 0;
  36.     padding: 0;
  37. }
  38.  
  39. img {
  40.     padding: 0;
  41.     display: block;
  42.     margin: 0 auto;
  43.     max-height: 100%;
  44.     max-width: 100%;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <a href="$IMG0"><img src="$IMG0" title="$TXT_NEXT"/></a>
  50. </body>
  51. </html>
  52. EOF
  53. scp $INDEX $PUBLISHING_HOST:$PUBLISHING_DIR
  54.  
  55. # run webcam
  56.  
  57. for (( ; ; ))
  58. do
  59.    fswebcam --banner-colour \#FF000000 --line-colour \#FF000000 --text-colour \#FF00FF --top-banner --shadow --font :20 -r 1280x720 $IMG1
  60.    scp $IMG1 $PUBLISHING_HOST:$PUBLISHING_DIR
  61.    ssh $PUBLISHING_HOST "cd "$PUBLISHING_DIR" ; mv "$IMG1" "$IMG0
  62.    mv $IMG1 $IMG0
  63.    echo
  64.    echo "New image uploaded. "$TXT_NEXT" Press CTRL+C to stop webcam..."
  65.    echo
  66.    sleep $INTERVAL_IN_SECONDS
  67. done

Raw Paste


Login or Register to edit or fork this paste. It's free.