Register
It is currently Thu Oct 23, 2014 12:38 am

Need an update if it is possible


All times are UTC - 6 hours


Post new topic Reply to topic  [ 13 posts ] 
Author Message
 PostPosted: Tue Jan 12, 2010 12:23 pm   

Joined: Sun Oct 25, 2009 6:42 pm
Posts: 18
A little while ago, members of this groups helped me with the following script. I log onto a shipping channel webcam, which updates every 60 seconds. So the following script grabs a photo of my screen every 60 seconds and in this way I get a picture of many of the ships that pass through. This works for me as the shipping channel is in Australia and it is light there when it is dark here, so this script usually runs at night when I am in bed.

# numberofloops=480; for i in $(seq -w 1 $numberofloops); do scrot "$(date +%Y-%m-%d)_$i.png"; sleep 60; done; shutdown -h now

The problem is that when the webcam updates and it flows to my screen, it fairly often does not load the whole picture. It loads from the top down and often I only get half the picture and can miss a ship. If I am sitting at the computer when this happens, and hit the reload button on my Firefox browser, the picture will be re-sent and come down completely.

So my question is, can the bashscript be modified so that it initiates a request to the lab cam url. When I do this by hand, the picture usually loads fully. It will have to make this request every 60 seconds. Here is the link:

http://www.portofmelbourne.com/shipping ... n_cam2.asp

Thank you, Bill.


Top
 Profile  
 PostPosted: Wed Jan 13, 2010 3:32 pm   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Why take a screenshot... the image updates itself every time you refresh the link to it.

Code:
numberofloops=480; for ((i = 0; $i < $numberofloops; i++)); do wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O $(date +%Y-%m-%d)_$i.jpg; sleep 60; done; shutdown -h now

Human readable version:
Code:
#!/bin/bash
numberofloops=480;
for ((i = 0; $i < $numberofloops; i++)); do
    wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O $(date +%Y-%m-%d)_$i.jpg;
    sleep 60;
done;
shutdown -h now


it just downloads the webcam image displayed on that page you linked and names the file according to your previous schema

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Thu Jan 14, 2010 9:56 pm   

Joined: Sun Oct 25, 2009 6:42 pm
Posts: 18
Thank you Erik, I will set it up. Bill.


Top
 Profile  
 PostPosted: Fri Jan 15, 2010 1:11 pm   

Joined: Sun Oct 25, 2009 6:42 pm
Posts: 18
fredrik.eriksson wrote:
Why take a screenshot... the image updates itself every time you refresh the link to it.

Code:
numberofloops=480; for ((i = 0; $i < $numberofloops; i++)); do wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O $(date +%Y-%m-%d)_$i.jpg; sleep 60; done; shutdown -h now

Human readable version:
Code:
#!/bin/bash
numberofloops=480;
for ((i = 0; $i < $numberofloops; i++)); do
    wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O $(date +%Y-%m-%d)_$i.jpg;
    sleep 60;
done;
shutdown -h now


it just downloads the webcam image displayed on that page you linked and names the file according to your previous schema

Best regards
Fredrik Eriksson


Hello Erik,

I ran the script and it worked fine. It saves me some work as all I get now is the image and not the whole screen. It saves me have to trim with Gimp. It also saved me from having to convert from *.png to *.jpg.

It has not really solved my problem as images still half load from time to time. Additionally, sometimes the site does not load at all which is not really the fault of the script. I get "Loading *.jpg failed. Loading Meta information failed."

The main problem is that when it finishes running and "shutdown -h now" reaches the cursor, it simply sits there and does not shut the unit down. It waits for me to press "Enter" and when I do, it goes ahead and shuts the unit down.

All the best,

Bill.


Top
 Profile  
 PostPosted: Mon Jan 18, 2010 7:31 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
The shutdown problem is just a case of getting the command options right. You may have a different version of shutdown so I suggest you check 'man shutdown' to see which options you actually need. On my system for example I'd use 'shutdown -P now'. And, of course, it expects to be run as root :)

As for failing to grab the picture that seems more of a connection or server issue. Maybe the script could attempt to download it again on failure like so;

Code:
#!/bin/bash
numberofloops=480;
for ((i = 0; $i < $numberofloops; i++)); do
    if ! wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O $(date +%Y-%m-%d)_$i.jpg
    then
      sleep 1 # this just gives the server/connection an extra second to sort itself out
      wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O $(date +%Y-%m-%d)_$i.jpg
    fi
    sleep 60;
done;
shutdown -P now


It's tricky to setup something that will fail half way through a download so I haven't tested that.
My version of wget has an option to setup retries also. If the server believes it's sending the whole image then this will not work.

You could instead maybe try testing the size of the resulting download and retry if the pic is too small;

Code:
date=$(date +%Y-%m-%d)
wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O ${$date}_$i.jpg
if [ "$(ls -s ${date}_$i.jpg | awk '{ print $1 }')" -lt 6000 ] # asks if file is smaller than 6000 bytes
then
  wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O ${$date}_$i.jpg
fi


I moved the date string into a variable to avoid messy recursive subshells.

I hope this helps a little :)

DW


Top
 Profile  
 PostPosted: Mon Jan 18, 2010 10:20 am   

Joined: Sun Oct 25, 2009 6:42 pm
Posts: 18
Thank you once again Erik, I will work on your suggestions.

Bill. :)


Top
 Profile  
 PostPosted: Mon Jan 18, 2010 3:37 pm   

Joined: Sun Oct 25, 2009 6:42 pm
Posts: 18
Sorry Darthwavy, my presumption was wrong. Thank you for your input, I will work on it.

Bill. :)


Top
 Profile  
 PostPosted: Mon Jan 18, 2010 4:07 pm   

Joined: Sun Oct 25, 2009 6:42 pm
Posts: 18
The first script above, that waited 1 second and then polled again did not work. So I ran the second script as follows:

#!/bin/bash
numberofloops=20;
for ((i = 0; $i < $numberofloops; i++)); do
date=$(date +%Y-%m-%d)
wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O ${$date}_$i.jpg
if [ "$(ls -s ${date}_$i.jpg | awk '{ print $1 }')" -lt 30000 ] # asks if file is smaller than 6000 bytes
then
wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O ${$date}_$i.jpg
fi
sleep 60;
done;
shutdown -P now

and got the following result. Maybe I did not put it together right or something:

bash: ${$date}_$i.jpg: bad substitution

Thank you,

Bill.


Top
 Profile  
 PostPosted: Tue Jan 19, 2010 3:35 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Code:
${$date}_$i.jpg

That should be
Code:
${date}_$i.jpg


It doesn't like ${$ references.

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Tue Jan 19, 2010 5:21 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
yup sorry, they were typos


Top
 Profile  
 PostPosted: Tue Jan 19, 2010 11:22 am   

Joined: Sun Oct 25, 2009 6:42 pm
Posts: 18
Thank you made the "date" change and the script ran. Following is what I ran:

#!/bin/bash
numberofloops=20;
for ((i = 0; $i < $numberofloops; i++)); do
date=$(date +%Y-%m-%d)
wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O ${date}_$i.jpg
if [ "$(ls -s ${date}_$i.jpg | awk '{ print $1 }')" -lt 30000 ] # asks if file is smaller than 30000 bytes
then
wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O ${date}_$i.jpg
fi
sleep 60;
done;
shutdown -h now

It fired 40 times but I only ended up with ten images?? Following is a sample of what was written to the screen when the script ran:

--2010-01-19 11:42:22-- http://www.portofmelbourne.com/webmedia/loncam2.jpg
Resolving www.portofmelbourne.com... 203.12.234.48
Connecting to www.portofmelbourne.com|203.12.234.48|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 32886 (32K) [image/jpeg]
Saving to: “2010-01-19_0.jpg”

100%[==========================================================>] 32,886 37.7K/s in 0.9s

2010-01-19 11:42:24 (37.7 KB/s) - “2010-01-19_0.jpg” saved [32886/32886]

--2010-01-19 11:42:24-- http://www.portofmelbourne.com/webmedia/loncam2.jpg
Resolving www.portofmelbourne.com... 203.12.234.48
Connecting to www.portofmelbourne.com|203.12.234.48|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 32886 (32K) [image/jpeg]
Saving to: “2010-01-19_0.jpg”

100%[==========================================================>] 32,886 37.7K/s in 0.9s

2010-01-19 11:42:25 (37.7 KB/s) - “2010-01-19_0.jpg” saved [32886/32886]

--2010-01-19 11:43:25-- http://www.portofmelbourne.com/webmedia/loncam2.jpg
Resolving www.portofmelbourne.com... 203.12.234.48
Connecting to www.portofmelbourne.com|203.12.234.48|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 34240 (33K) [image/jpeg]
Saving to: “2010-01-19_1.jpg”

100%[==========================================================>] 34,240 38.1K/s in 0.9s

2010-01-19 11:43:26 (38.1 KB/s) - “2010-01-19_1.jpg” saved [34240/34240]

--2010-01-19 11:43:26-- http://www.portofmelbourne.com/webmedia/loncam2.jpg
Resolving www.portofmelbourne.com... 203.12.234.48
Connecting to www.portofmelbourne.com|203.12.234.48|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 0 [image/jpeg]
Saving to: “2010-01-19_1.jpg”

[ <=> ] 0 --.-K/s in 0s

2010-01-19 11:43:27 (0.00 B/s) - “2010-01-19_1.jpg” saved [0/0]

--2010-01-19 11:44:27-- http://www.portofmelbourne.com/webmedia/loncam2.jpg
Resolving www.portofmelbourne.com... 203.12.234.48
Connecting to www.portofmelbourne.com|203.12.234.48|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7300 (7.1K) [image/jpeg]
Saving to: “2010-01-19_2.jpg”

100%[==========================================================>] 7,300 25.1K/s in 0.3s

2010-01-19 11:44:28 (25.1 KB/s) - “2010-01-19_2.jpg” saved [7300/7300]

--2010-01-19 11:44:28-- http://www.portofmelbourne.com/webmedia/loncam2.jpg
Resolving www.portofmelbourne.com... 203.12.234.48
Connecting to www.portofmelbourne.com|203.12.234.48|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 32768 (32K) [image/jpeg]
Saving to: “2010-01-19_2.jpg”

100%[==========================================================>] 32,768 37.6K/s in 0.8s

2010-01-19 11:44:29 (37.6 KB/s) - “2010-01-19_2.jpg” saved [32768/32768]

--2010-01-19 11:45:29-- http://www.portofmelbourne.com/webmedia/loncam2.jpg
Resolving www.portofmelbourne.com... 203.12.234.48
Connecting to www.portofmelbourne.com|203.12.234.48|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 32353 (32K) [image/jpeg]
Saving to: “2010-01-19_3.jpg”

100%[==========================================================>] 32,353 36.9K/s in 0.9s

2010-01-19 11:45:31 (36.9 KB/s) - “2010-01-19_3.jpg” saved [32353/32353]

--2010-01-19 11:45:31-- http://www.portofmelbourne.com/webmedia/loncam2.jpg
Resolving www.portofmelbourne.com... 203.12.234.48
Connecting to www.portofmelbourne.com|203.12.234.48|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 32353 (32K) [image/jpeg]
Saving to: “2010-01-19_3.jpg”

100%[==========================================================>] 32,353 37.3K/s in 0.8s

2010-01-19 11:45:33 (37.3 KB/s) - “2010-01-19_3.jpg” saved [32353/32353]

--2010-01-19 11:46:33-- http://www.portofmelbourne.com/webmedia/loncam2.jpg
Resolving www.portofmelbourne.com... 203.12.234.48
Connecting to www.portofmelbourne.com|203.12.234.48|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 32320 (32K) [image/jpeg]
Saving to: “2010-01-19_4.jpg”

100%[==========================================================>] 32,320 36.8K/s in 0.9s

2010-01-19 11:46:34 (36.8 KB/s) - “2010-01-19_4.jpg” saved [32320/32320]

--2010-01-19 11:46:34-- http://www.portofmelbourne.com/webmedia/loncam2.jpg
Resolving www.portofmelbourne.com... 203.12.234.48
Connecting to www.portofmelbourne.com|203.12.234.48|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 24576 (24K) [image/jpeg]
Saving to: “2010-01-19_4.jpg”

100%[==========================================================>] 24,576 28.3K/s in 0.8s

Thanks again,

Bill.


Top
 Profile  
 PostPosted: Wed Jan 20, 2010 11:22 am   

Joined: Sun Oct 25, 2009 6:42 pm
Posts: 18
Further on the above script. I ran it again and what happens is that it fires twice and saves once. That is if it produces say 2010-1.jpg, it will immediately repeat that and save 2010-1.jpg. However when I check the images I only get the 20 images that I set the script to produce. Is it possible that the second image is simply overwriting the first image so that the end result is only one image?

Whatever the case may be the problem of only getting half images from time time still exists and out of the 20 images that I set the script for, there was two blanks.

Thank you,

Bill.


Top
 Profile  
 PostPosted: Fri Jan 22, 2010 1:02 pm   

Joined: Sun Oct 25, 2009 6:42 pm
Posts: 18
DarthWavy wrote:
The shutdown problem is just a case of getting the command options right. You may have a different version of shutdown so I suggest you check 'man shutdown' to see which options you actually need. On my system for example I'd use 'shutdown -P now'. And, of course, it expects to be run as root :)

As for failing to grab the picture that seems more of a connection or server issue. Maybe the script could attempt to download it again on failure like so;

It's tricky to setup something that will fail half way through a download so I haven't tested that.
My version of wget has an option to setup retries also. If the server believes it's sending the whole image then this will not work.

You could instead maybe try testing the size of the resulting download and retry if the pic is too small;

#!/bin/bash
numberofloops=6;
for ((i = 0; $i < $numberofloops; i++)); do
date=$(date +%Y-%m-%d)
wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O ${date}_$i.jpg
if [ "$(ls -s ${date}_$i.jpg | awk '{ print $1 }')" -lt 30000 ] # asks if file is smaller than 30000 bytes
then
sleep 4
wget http://www.portofmelbourne.com/webmedia/loncam2.jpg -O ${date}_$i.jpg
fi
sleep 60;
done;shutdown -h now


The shutdown such as "shutdown -h now" was correct and worked on my initial string. When it didn't work I noticed that the command was not at the cursor but four or five spaces away from it. I was using the human readable form of the string. When I ran the script with the shutdown like so: "done;shutdown -h now" it went ahead and shut the system down.

The above string works best. The failure to load and the half downloads are still there and I think that, as suggested earlier, to be a server problem. I have run the original string on the Panama Locks with only a 10 second sleep time and all the pictures come through just fine.

Two more advantages for me is that I only have to trim. Secondly, and most useful, it will work in the background and I can use the computer for other work.

So a big thank you to all who contributed to my request.

Bill.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP