Dec 312009
 

Although it could seem an oxymore, sort something in randomic order might be usefl sometimes.

Give a look to the script below, which I’m writing here for future reference.

#!/bin/bash
#
# This script creates a list of file or symbolic link to pictures in a directory
# The pictures are dynamically selected within a library of thousands
# This is to allow a wireless frame to display daily an ever changing list
# of pictures

# Define variable to be the target directory where we put the link/pictures
# This directory is regularly scanned by MediaTomb, the uPnP server talking to
# the digital frame

# Define variable to be the root directory where it will start to scan
scandir=/media/allphotos

# Clean previous contents of the directory used for streaming
cd /var/streampix
rm -rf *

# Define cycle to set the max number of photos to be displayed
# (like from 1 to 50 repeat)
for i in `seq 1 50`

# list the dir, pick a random file, add to the list
do
y="$(find $scandir -type f -iregex ‘.*\.\(bmp\|gif\|jpg\|png\)$’ | sort -R | head -1)"
cp "$y" /var/streampix/
done

Enjoy!