Simple bash script for making a 'new downloads' folder w/ symlinks
Posted: April 1st, 2009, 8:50 pm
Figured somewhere out there might like this one I use:
This gives me a set of symlinks in /files/New along the lines of:
Which is nice for those RSS feeds when you don't want to login to see what's new.
It's a bit of a ghetto hack to find the actual file name after sab has renamed it, but it works pretty well.
Code: Select all
#!/bin/bash
maxage=14 # How many days to keep the links for
dt=`date +%m-%d` # Date format (see man date)
linkpath="/files/New" # Where to put the links
realf=`ls -t "$1" | egrep '*\.(avi|mkv|mpg)' | head -n 1`
ln -s "$1/$realf" "$linkpath/$dt-$5-$realf"
echo ln -s "$1/$realf" "$linkpath/$dt-$5-$realf"
# Remove anything too old
find $linkpath -mtime +$maxage -exec rm -rf {} \;
This gives me a set of symlinks in /files/New along the lines of:
Code: Select all
lrwxrwxrwx 1 root root 36 Mar 30 20:27 03-30-tv-24 07x16.mkv -> /raid/files/Video/TV/24/24 07x16.mkv
lrwxrwxrwx 1 root root 44 Mar 30 20:08 03-30-tv-Heroes 03x21.mkv -> /raid/files/Video/TV/Heroes/Heroes 03x21.mkv
lrwxrwxrwx 1 root root 42 Mar 30 19:47 03-30-tv-House 05x19.mkv -> /raid/files/Video/TV/House/House 05x19.mkv
lrwxrwxrwx 1 root root 101 Mar 31 10:15 03-31-tv-The.Daily.Show.2009.03.30.PDTV.XviD-LMAO.avi -> /files/Video/TV/The.Daily.Show.2009.03.30.PDTV.XviD-LMAO/the.daily.show.2009.03.30.pdtv.xvid-lmao.avi
lrwxrwxrwx 1 root root 94 Apr 1 02:45 04-01-tv-The.Daily.Show.03.31.2009.PDTV.XviD-iHT.avi -> /files/Video/TV/The.Daily.Show.03.31.2009.PDTV.XviD-iHT/the.daily.show.03.31.2009.xvid-iht.avi
lrwxrwxrwx 1 root root 94 Apr 1 18:42 04-01-tv-the.daily.show.03.31.2009.xvid-iht.avi -> /files/Video/TV/The.Daily.Show.03.31.2009.PDTV.XviD-iHT/the.daily.show.03.31.2009.xvid-iht.avi
It's a bit of a ghetto hack to find the actual file name after sab has renamed it, but it works pretty well.