I have a list of files that must exist in a remote directory before I send out a confirmation email. For example, my list is: file_list=example.txt testfile.txt. I know how to test if each individual file exists as such:
ssh [email protected] "test -e /path/to/file/example.txt"
if [ $? -eq 0 ]; then
echo -e "Email body" | mail -s "File exists." "[email protected]"
fi
But how can I hit each file in the list and confirm that all files exist in this remote directory? Say three out of four were successfully pushed via sftp, I'd need to exit with an e-mail error to my group only saying go check it out rather than proceeding to email the client that all files are available. The logic is perhaps something like:
ssh [email protected] "test - [$file_list]"
if [they all exist]; then
successful -- email the client
else
error -- email your group
exit
fi