-   Linux - Software (
-   -   How to wget a random file from a website, then use FEH to view it. (

xmrkite 10-16-2006 01:51 PM

How to wget a random file from a website, then use FEH to view it.

What I want to do is have it so that I run wget and FEH (an image viewer) and each time they are run, a different, random image file is download with wget and run in feh.

Now here is the tricky part...the images are online and are cool Garfield comics. They are named according to the date. For example:

As you can see, the year is the folder that the image lies in, and the filename is "ga" then two digit year, month, date then .gif

How would i create a script to randomly download just one image, then use feh to show that image?

Some of the years would start with 19 and some with 20, and i need to make sure i don't use dates like sep 31 or feb 29 (unless it's a leap year).

Any help would be great, even a point in the right direction is appreciated.


unSpawn 10-16-2006 05:22 PM

Here's an example of an download-and-display script:
So all you have to do is randomise the URI.


doThis() { RAND=${RANDOM:0:4}; }
doThat() { doThis; [ $RAND -le 2800 ] && FILE=`date +'/%Y/qa/%y%m%d.gif' --date="$RAND days ago"` || doThat ; }
doThat &&FILE="${FILE}"
/some/app "$FILE"
exit 0

Now you can use the $FILE variable with the fetcher to get the file and display it on your desktop or script it to save it with wget to a tempfile and display with your viewer.

matthewg42 10-17-2006 08:09 AM

Here's a way to do it with perl:


#!/usr/bin/perl -w

use Date::Parse;
use Date::Format;

my $earliest = str2time("2006:01:01");
my $get_time = $earliest + int( rand() * (time() - $earliest ));
my $url = time2str("", $get_time);
system("feh", $url);

  1. You can set the earliest date by modifying the 2006:01:01 to whatever is the earliest date for which a URL exists (YYYY MM DD format).
  2. feh is called on the URL directly. No need for wget first.
  3. Don't forget to chmod a+x the file before trying to run it.
  4. All your scripts are belong to us.

xmrkite 10-17-2006 02:26 PM

Hey guys, thanks for the help.

I was able to get it going nicely.

All times are GMT -5. The time now is 01:37 AM.