I have a folder named images on my linux box.
This folder is connected to a website and the admin of the site has the ability to add pictures to this site. However, when a picture is added, I want a command to run resizing all of the pictures a directory.
In short, I want to know how I can make the server run a specific command when a new file is added to a specific location.
I don’t know how people are uploading content to this folder, but you might want to use something lower-tech than monitoring the directory with inotify.
If the protocol is FTP and you have access to your FTP server’s log, I suggest tailing that log to watch for successful uploads. This sort of event-triggered approach will be faster, more reliable, and less load than a polling approach with traditional cron, and more portable and easier to debug than something using inotify.
The way you handle this will of course depend on your FTP server. I have one running vsftpd whose logs include lines like this:
The
UPLOADline only gets added when vsftpd has successfully saved the file. You could parse this in a shell script like this:If you’re using an HTTP upload tool, see if that tool has a text log file it uses to record incoming files. If it doesn’t consider adding some sort of logger function to it, so it’ll produce logs that you can
tail.