Find the answer to your Linux question:
Results 1 to 3 of 3
I need a bash script to get the latest image from "http://radar.weather.gov/RadarImg/NCR/ABX/" I know about wget but I'm not sure how to script this so it automatically gets the latest ...
  1. #1
    Just Joined!
    Join Date
    Aug 2008
    Posts
    2

    Bash Script to obtain latest image

    I need a bash script to get the latest image from "http://radar.weather.gov/RadarImg/NCR/ABX/"

    I know about wget but I'm not sure how to script this so it automatically gets the latest and only get any new file since the last DL. I will have a cron job to trigger off the script.

    I will also be using lines like:
    Code:
    #!/bin/bash
    ...
    #Get latest image(s)
    ...
    #re-create animated gif adding new frame
    if [ -ne anim.gif ]
       gifsicle -merge --loop --optimize=2 --disposal=previous * > anim.gif
    else
       for i in $NEW_FILE
           gifsicle --merge --append $NEW_FILE --loop --optimize=2 --disposal=previous anim.gif > anim.gif
    fi
    to create an animated gif from all the collected images.

    this file will be used in an internal webpage looking like:
    Code:
    <html>
       <head>
          <meta http-equiv="refresh" content="120">
          <style rel="stylesheet" type="text/css">
             #image0, #image1, #image2, #image3, #image4, #image5, #image6, #image7, #image8, #image9 {position:absolute; left:9px; top:9px;}
             #image0 img, #image1 img, #image2 img, #image3 img, #image4 img, #image5 img, #image6 img, #image7 img, #image8 img, #image img9 {border-style:none;}
          </style>
       </head>
       <body>
          <div>
             <div style="visibility: visible;" id="image0"><img style="z-index: 0;" src="http://radar.weather.gov/Overlays/Topo/Short/ABX_Topo_Short.jpg" alt="Latest radar image from the Wilmington, OH radar and current weather warnings"></div>
             <!-- <div style="visibility: hidden; " id="image1"><img style="z-index: 1;" src="http://radar.weather.gov/RadarImg/N0R/ABX_N0R_0.gif" name="conditionalimage" alt="Latest radar image from the Wilmington, OH radar and current weather warnings"></div>
             <div style="visibility: visible;" id="image1"><img style="z-index: 1;" src="http://radar.weather.gov/RadarImg/NCR/ABX_NCR_0.gif" name="conditionalimage" alt="Latest radar image from the Wilmington, OH radar and current weather warnings"></div> -->
             <div style="visibility: visible;" id="image1"><img style="z-index: 1;" src="http://SERVER/radar/anim.gif" name="conditionalimage" alt="Latest radar image from the Wilmington, OH radar and current weather warnings"></div>
             <div style="visibility: visible;" id="image2"><img style="z-index: 2;" src="http://radar.weather.gov/Overlays/County/Short/ABX_County_Short.gif" alt="Latest radar image from the Wilmington, OH radar and current weather warnings"></div>
             <div style="visibility: hidden; " id="image3"><img style="z-index: 3;" src="http://radar.weather.gov/Overlays/Rivers/Short/ABX_Rivers_Short.gif" alt="Latest radar image from the Wilmington, OH radar and current weather warnings"></div>
             <div style="visibility: visible;" id="image4"><img style="z-index: 4;" src="http://radar.weather.gov/Overlays/Highways/Short/ABX_Highways_Short.gif" alt="Latest radar image from the Wilmington, OH radar and current weather warnings"></div>
             <div style="visibility: visible;" id="image5"><img style="z-index: 5;" src="http://radar.weather.gov/Overlays/Cities/Short/ABX_City_Short.gif" alt="Latest radar image from the Wilmington, OH radar and current weather warnings"></div>
             <div style="visibility: visible;" id="image6"><img style="z-index: 6;" src="http://radar.weather.gov/Warnings/Short/ABX_Warnings_0.gif" alt="Latest radar image from the Wilmington, OH radar and current weather warnings" border="0"></div>
             <div style="visibility: visible;" id="image7"><img style="z-index: 7;" src="http://radar.weather.gov/Legend/N0R/ABX_N0R_Legend_0.gif" name="conditionallegend" alt="Latest radar image from the Wilmington, OH radar and current weather warnings" border="0"></div>
          </div>
       </body>
    </html>
    Thanks for your help.

  2. #2
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    for the "getting the latest images" part, you can use wget this way:

    Code:
    wget -O - http://radar.weather.gov/RadarImg/NCR/ABX/ | awk  '/Apache/{f=0}{$1=$1} !/^$/ && f; /Parent/{f=1};' FS="<[^>]+>|\n+" index.html | awk '!/^[ \n]+$/{print $1}' | while read F
    do
      wget http://radar.weather.gov/RadarImg/NCR/ABX/$F
    done

  3. #3
    Just Joined!
    Join Date
    Aug 2008
    Posts
    2

    Ah the MAN pages

    A copy past from the man page (which for wget is HUGE)

    Code:
    You want to download all the GIFs from a directory on an HTTP server. You tried wget http://www.server.com/dir/*.gif, but that didn't work because HTTP retrieval does not support globbing. In that case, use:
    
        wget -r -l1 --no-parent -A.gif http://www.server.com/dir/
    
        More verbose, but the effect is the same. -r -l1 means to retrieve recursively, with maximum depth of 1. --no-parent means that references to the parent directory are ignored, and -A.gif means to download only the GIF files. -A "*.gif" would have worked too.
    So here is what I have so far (please help me optimize this)
    Code:
    cd /opt/radar/images
    wget -nH -nd -nc -r -l1 --no-parent -A.gif "http://radar.weather.gov/RadarImg/NCR/ILN/"
    rm anim.gif
    gifsicle -merge --loop --disposal=previous * > anim.gif

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...