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 is one for yesterday. However no matter which date I use, the 30 or the 31, the return code is the same.
What I am looking to check is the return status of ssh which I thought should be return status of the remotely executed command I thought that the 'if statement' would exit with a 0 if the 'ls -ltr' worked and something greater than zero, or false if the 'ls -ltr' did not work. I would think that the 'if' statement would look at the return status of the shh, which should be the return status of the remotely executed command - or the 'ls -ltr'
How do i get thie to work?
this is for the 30 - which is on the remote host, and is successful
casper@host:/scripts$ ssh -q -T user@capserbox "ls -ltr /home/DropBox/transactions_20141230.csv"
-rw-r--r-- 1 rr_prd 2233047 Dec 31 07:26 /home/DropBox/transactions_20141230.csv
and this is for the 31 which there is no report yet for the 31, so it is unsuccessful
casper@host:/scripts$ ssh -q -T user@capserbox "ls -ltr /home/DropBox/transactions_20141231.csv"
/home/DropBox/transactions_20141231.csv not found
casper@host:/scripts$
I flip the date with the comment out hashtag
casper@host:/scripts$ ssh -q -T user@capserbox "ls -ltr /home/DropBox/transactions_20141231.csv"
/home/DropBox/transactions_20141231.csv not found
casper@host:/scripts$
#!/bin/bash
today=$(/bin/date +%Y%m%d)
#today="20141230"
echo $today
if ssh -q -T user@capserbox "ls -ltr /home/DropBox/transactions_$today.csv" > /dev/null 2>&1 ;
then
echo "this worked"
else
echo "this did not work"
fi
However - when i use the script for both dates - it is successful, when for the 31, it really should return "this did not work"
casper@host:/scripts$
casper@host:/scripts$ vim offshore_check
casper@host:/scripts$ ./offshore_check
20141230
this worked
casper@host:/scripts$ vim offshore_check
casper@host:/scripts$ ./offshore_check
20141231
this worked
casper@host:/scripts$
casper@host:/scripts$