I need to check that a transacions file is published on a remote host. There is no transactions code published for today the 31 of December. I know that for certain. There i
Similar issues have been discussed here many times, see scp return code discussion 1
and 300+ answers when searching for scp errors
but to give you a working answer, consider trying this
if
ssh -q -T user@capserbox "ls -ltr /home/DropBox/transactions_${today}.csv" \
| grep -q "transactions_${today}\.csv" ;
then
echo "this worked"
else
echo "nope"
fi
Sorry, I don't have any way to test this.
IHTH.
The "if" construct that you're using should work, and it does work for me:
$ if ssh -q -T localhost "ls -ltr /does/not/exist"; then echo succeeded; else echo failed; fi
Password:
ls: /does/not/exist: No such file or directory
failed
I notice that the error printed by your ls
program is worded differently than the error that I got (and I tried two different systems). "file not found" in your case, "ls: file: No such file or directory" in mine. My suspicion is that the ls
command which you're invoking here isn't the typical modern Unix command. You may be running a nonstandard version, a non-Unix version, or something very old, and it may not actually be exiting with a non-zero exit code for this particular error.
file="/home/DropBox/transactions_20141231.csv"
ssh -q -T user@capserbox "test -e $file"
ret="$?"
case $ret in
0)
echo "$file exists"
;;
1)
echo "$file does not exist"
;;
*)
echo "other problem"
;;
esac