Basic bash Linux - display random gif from directory on timer, then cycle to next random gif - loop forever

Experts,

In conjunction with this utility (http://www.imagemagick.org/) to display gifs; I'd like to combine it with a script that's on a continual loop and cycles through random gifs.  I've got a directory with TONs of gifs, and I'd like to launch the script on start up, and then continue until the end of time.

Is this at all possible, and if it is could somebody point me in the right direction on where to learn how to do this?

Any assistance will be greatly appreciated.  This is for a non-gui Linux distro.
LVL 5
usslindstromAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Frosty555Commented:
Where exactly are the GIFs being displayed? In a client's webbrowser? In a desktop window on the Linux machine?
0
nemws1Database AdministratorCommented:
Can the images repeat within a loop (ie truly random image each time) or should each image only be displayed once until *all* images have been displayed, then it can be displayed again?
0
nemws1Database AdministratorCommented:
If you have GNU's sort installed, you can use the '-R' option to sort randomly.  This assumes you want the latter of my described situations (display all in random order before any repeats).  Also, the ImageMagick 'display' option displays the image until you quit it.  So this does *not* run automatically forever.

#!/bin/bash
IMGDIR=/path/to/your/images

while :
do
        IMAGES=`/bin/ls $IMGDIR | sort -R`
        for img in $IMAGES
        do
                display "$IMGDIR/$img"
        done
done

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

nemws1Database AdministratorCommented:
If you want zero interaction, this will kill 'display' after DISPLAY_TIME seconds.
#!/bin/bash
IMGDIR=/path/to/your/images
DISPLAY_TIME=10

while :
do
    IMAGES=`/bin/ls $IMGDIR | sort -R`
    for img in $IMAGES
    do
        display "$IMGDIR/$img" &
        DISPLAY_PID=$!
        sleep $DISPLAY_TIME
        kill $DISPLAY_PID
    done
done

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
usslindstromAuthor Commented:
Wow - these posts are great!  - Give me a minute to take them in and try to understand them.

-- Where exactly are the GIFs being displayed? In a client's webbrowser? In a desktop window on the Linux machine?
  This is on the local client machine only.  This is actually from the use of a Raspberry Pi w/2.5" screen attached, mounted to the front of a box I threw together.

-- Can the images repeat within a loop (ie truly random image each time) or should each image only be displayed once until *all* images have been displayed, then it can be displayed again?
   Truthfully, it doesn't matter in this instance, truly random or sequenced through all prior to going through it again.  Your script looks like it will accomplish this flawlessly.  I'm fairly decent in vbs, so I get the basics of what you're showing me.  Bash can be a bit of a bear to understand though.

If you don't mind me asking, the while loop here, you didn't set a conditional statement, so that basically means it will never terminate?  (If so, that's pretty wild.  :) )
0
nemws1Database AdministratorCommented:
Images are displayed in a window on the Linux desktop - you mentioned the ImageMagick package, which has a 'display' program and that's what that script uses.

"while :" basically means the condition "true" is "true", which is always the case. :)
0
nemws1Database AdministratorCommented:
BTW - here's a great use of 'while :' for a quick and dirty clock.  You should know, to break out of these loops, do a CTRL-C.

#!/bin/bash
while :
do
    date
    sleep 1
done

Open in new window

0
usslindstromAuthor Commented:
Outstanding, thank you very much for the solution, as well as explination.  Much appreciated!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.