0

I have a set of directories that have files in them for use with LiquidSoap for use with IceCast2

Currently, every time I remove a file or add a file, I have to edit the txt file listing the mp3s to play manually

What I would like to do is create a script, or a cron job, t automatically create a simple list of the fill path to the mp3s across the folders that is completely regenerated each time.

I say it needs to be regenerated for sake of deleted files being removed from the file


The files are in directories suck as

/home/user1/files/foo 1/
/home/user1/files/foo 2/
etc...

and the contents are

this file is called this.mp3
another name for a file.mp3
etc...

I would like to have a script or cron that creates a txt file with the contents of each folder that ends up like

/home/user1/files/foo 1/this file is called this.mp3
/home/user1/files/foo 1/another name for a file.mp3
/home/user1/files/foo 1/this is a cool filename.mp3
/home/user1/files/foo 2/moar files.mp3
/home/user1/files/foo 2/okay this is getting old.mp3

But if I removed /home/user1/files/foo 1/this file is called this.mp3 then it would leave the txt file on the next generation, and if I added yet another file.mp3 to one of the folders, it would be added to the txt file

Currently running Ubuntu Server 13.04, and am able to install packages, if needed, although wold like to use simple scripts/crons

1
  • 1
    Look into incron too; it responds to changes in directories, so it would be a good fit for this task, instead of a time based cron. Commented Jul 30, 2013 at 1:39

3 Answers 3

1

See find:

find "/home/user1/files/foo 1/" "/home/user1/files/foo 2/" > output.txt
4
  • Wow, I feel dumb now...that's like...linux basics.... Commented Jul 30, 2013 at 1:28
  • although is there any way to remove the directory listing from the fist line of the find in each folder? Commented Jul 30, 2013 at 1:30
  • You can use find -mindepth 1. Commented Jul 30, 2013 at 1:36
  • To exclude directory names from the listing, add -type f. This will list only regular files.
    – Niccolo M.
    Commented Aug 6, 2013 at 16:13
1

Tip: You can also do LC_ALL=C ls -lR | gzip > listing.ls-lR.gz. Midnight Commander lets you view such files (unofficially known as "ls-lR") as if they were a real filesystem.

0

(Assuming that you're running Linux) The tool you're looking for is inotify (see "man inotify"). It's possible to set it up to run

find "/home/user1/files/foo 1/" "/home/user1/files/foo 2/" > output.txt

whenever a file is added to (or deleted from) the target directories.

For Ubuntu, you'll need to install the inotify-tools package. This installs two binaries: inotifywatch and inotifywait. A good example of scripting what you need is at: http://exyr.org/2011/inotify-run/

I use something similar for my own home-grown Liquidsoap-based jukebox.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .