Hello,
I wrote a basic script that works however I am was wondering if it could be sped up. I am comparing files over ssh to remove the file from the source server directory if a match occurs. Please Advise me on my mistakes.
#!/bin/bash
for file in `ls /export/home/podcast2/"$1" ` ; do
if [ "`ssh server1.stm ls /export/home/podcast/data2/$1/$file`" = "/export/home/podcast/data2/$1/$file" ]
then
rm -f /export/home/podcast2/$1/$file
fi
done
The -d option is used to set the delimiter between fields. If your xargs does not have this option, you can omit it; it will work fine except for filenames with spaces
That's understating the matter. It will not work properly for filenames with spaces, tabs, newlines, single quotes, and double quotes.
You can improve the robustness of the pipeline by passing the output of ssh through
tr '\n' '\0'
and using xargs' -0 option. This will render it impervious to any characters except embedded newlines in filenames (which I assume is very unlikely to occur unless someone has been drinking and admining). If you retool to use `find -print0`, then there'd be no need for the tr filtering and even embedded newlines would be handled properly.
Also, the rm command in the original post needs some quoting to prevent field splitting damage.