Copy webcam image to /var/www/html/weewx/image.jpg

230 views
Skip to first unread message

Rich Strle

unread,
Nov 22, 2020, 2:06:21 PM11/22/20
to weewx-user
My copy of weewx is running on a Raspberry Pi. I am trying to get an image from a webcam on my local network using wget, resizing the image using imagemagick, then put it in the /var/www/html/weewx/ folder so it will get uploaded to my web host.

wget --user=user --password=user  http://192.168.254.33/jpg/image.jpg?size=3 -O/var/www/html/weewx/image.jpg

I get a Permission denied error.

From there my plan was to use imagick to reduced the size of the file and include the image in the upload.

I as able to put this in a bash script and run a cron job to do this process to my /home/pi/Pictures/image.jpg folder but I can''t figure out how to copy the file to the html/weewx directory.

If there is a better way to do what I'm trying to accomplish I'm willing to try that.

Thanks in advance.

John Burricelli

unread,
Nov 22, 2020, 2:18:11 PM11/22/20
to weewx-user
I am doing something similar

What I did was run that under www-data user.  First I had to change the shell in /etc/passwd to look like this.

www-data:x:1028:33:www-data:/var/www:/bin/bash

once that is done you can sudo su - www-data and add the cron entry.

Another way would be to add the pi user to the www-data group and mess with the directory permissions.

Rich Strle

unread,
Nov 22, 2020, 4:44:01 PM11/22/20
to weewx-user
Thank you John. I have more questions. I'll try and be specific so the next person who wants to grab an image, resize it, and include it in the ftp process can go it easier.

Looking at my passwrd file I see: www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin

Would I remove the /nologin?

Can you explain this please? "once that is done you can sudo su - www-data and add the cron entry."

My bigger question is, where did weewx set permissions for itself? Does that happen in the install process?

vince

unread,
Nov 22, 2020, 6:34:04 PM11/22/20
to weewx-user
On Sunday, November 22, 2020 at 8:44:01 AM UTC-8 Rich Strle wrote:
Looking at my passwrd file I see: www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
Would I remove the /nologin?


Please don't do that.

www-data is the owner of the web 'data' and your webserver process likely runs as that user.
The nologin there ensures that if anybody/anything breaks security on your webserver running process, then they still wouldn't be able to get a shell and install/run malware etc.

What you want to do is:
  • put all your processing in a script
  • run that script as the non-privileged user 'pi' and write to scratch directories that pi can write to (/tmp or /var/tmp are likely places)
  • in your script, do the 'privileged' copy of the output file to the /var/www/html directory by prefacing your 'cp' command ala 'sudo cp'
  • and you'll likely want to set the permissions on the file in /var/www/html also with 'sudo chmod' 
(standard suggestion - if you're asking this you need to up your linux-fu a little - I always suggest looking at the free edx.org Linux Fundamentals course that literally a million folks have taken)

A simple script that grabs Google's logo image as an example would look something like:

   #!/bin/bash
   SCRATCH_FILE="/tmp/image.jpg"
   FINAL_OUTPUT="/var/www/html/image.jpg"

   # wget the file in quiet mode to a temporary location
   wget -q "${URL}" "${SCRATCH_FILE}"

   # copy it into place and fix up permissions via sudo
   sudo cp "${SCRATCH_FILE}" "${FINAL_OUTPUT}"
   sudo chown www-data "${FINAL_OUTPUT}"
   sudo chmod 644      "${FINAL_OUTPUT}"

This script did the right thing for me, FWIW.  You'll of course have to put in the right wget switches to grab your image from the camera, as well as doing any processing with ImageMagick etc. before you copy your image into the web tree, but this should give you a skeleton to start with that does the permission stuff...


Rich Strle

unread,
Nov 22, 2020, 7:47:33 PM11/22/20
to weewx...@googlegroups.com
Thanks very much Vince.

I appreciate your advice on the Linux Fundamentals course.

Rich Strle
309-824-9213
> --
> You received this message because you are subscribed to a topic in the Google Groups "weewx-user" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/979HfPDddwc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/ca47e7f4-cdd5-4989-92f1-6af8d1a154dan%40googlegroups.com.

Greg Sinclair

unread,
Nov 23, 2020, 2:35:04 PM11/23/20
to weewx-user
I do this by doing all the processing on the Pi capturing the image and then doing a sftp to place the image where weewx can find it.

Greg

salinois

unread,
Nov 23, 2020, 4:03:46 PM11/23/20
to weewx...@googlegroups.com

hello,

here, what I did to capture a video image and put it on the RPi server with the belchertown skin. I used an intermediate server, here a NAS. (freeNas).
1- Samsung Camera ----> FTP ----> Freenas.
2 - SCP transfer from RPi (weewx) ---> FreeNas -> / home / pi / transfer-images / "capture name"
3 - script to rename "capture name" ---> new name.jpg
4- cp "new name.jpg" ---> / var / www / html / weewx / belchertown / images /
5- to automate everything, this I created a batch that I put in crontab.

Patrick

You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/6b532573-933d-4e1b-b010-c54f4b8ee483n%40googlegroups.com.

Rich Strle

unread,
Nov 25, 2020, 1:17:23 AM11/25/20
to weewx-user
Thank you for all the suggestions. I need to take my linux-fu a lot.

Before I can move forward, I have a problem on my weather station Pi. On my 'dev' Pi this wget command works as expected wget --user=user --password=user  http://192.168.254.33/jpg/image.jpg?size=3 -O/home/pi/Pictures/image.jpg works as expected

When I run the same wget command on my weather station Pi I get an error message :schema Missing from wget. it makes the file but there isn't any data in the file. if I put the URL into a browser window I get the image I expect. 

if it matters, I am running WeeWX directly. I believe both Pi's have the same version of the operating system and I didn't change any permissions.

I'm out of ideas...

vince

unread,
Nov 25, 2020, 2:19:50 AM11/25/20
to weewx-user
We can't help much without an exact transcript of what you're seeing...your descriptions aren't quite enough for us.

It is likely you have quotes in there, or you're missing quotes, based on a google search for ":schema missing wget" and poking around the first few links.

Try putting quotes around the URL.  The question mark character in there can throw bash off.  You probably want a space after -O as well.

Rich Strle

unread,
Nov 28, 2020, 5:32:01 PM11/28/20
to weewx-user
Duh! There was an extra space between: password=user  http://192.168.254.33/jpg/image.jpg?size=3
                                                                                                    ^
Thanks everyone for your help. The march forward continues...
Reply all
Reply to author
Forward
0 new messages