Checking the exit status of a ssh remote command in bash

前端 未结 3 721
轻奢々
轻奢々 2020-12-20 02:59

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

3条回答
  •  别那么骄傲
    2020-12-20 03:25

    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.

提交回复
热议问题