I have this script below that will be daemonized and triggered possibly hundreds if not thousands of times by different users.
The script uses inotifywait to watch a folder for an upload and then move the uploaded file to its final destination for presentation, after rotating (backup/move) previous uploads. The code will be run against different upload folders that are created on the fly.
#!/bin/bash
db="$VAR1"/path/to/upload/folder/
s3="$VAR2"/path/to/remote/folder
inotifywait -m -r -e attrib "$db" |
while read dir ev file;
do
for dirnum in $(cd "$s3"; ls */*.png | sed 's%/.*%%' | sort -nr)
do
next=$(($dirnum + 1));
mv "$s3/$dirnum/post$dirnum.png" "$s3/$next/post$next.png";
done
mv "$db"/"$file" "$s3"/1/post1.png
done
What can I do to optimize it? Or should it be rewritten a faster programming language? Also, how can I test scripts under a certain amount of load?