algorhythm algorhythm - 8 months ago 26
Bash Question

Shell: Determine if file exists on another server true or false

I have an if statement I use to find if a file exists on another server. While testing with the file not on the other server it is returning true which suggests it is only looking on the current server even though I have used ssh to connect to the other server.

if [ 'ssh $USER@$IP_ADDRESS test -e -name "$IPADDRESS:$DIRECTORY/$FILE"' ];

Is there anyway that I can get this to work within the


You don't need to test again result returned by ssh, so no need in [].

ssh will return 0 (True) if remote test succeeded, so:

if `ssh $USER@$IP_ADDRESS test -e -name "$IPADDRESS:$DIRECTORY/$FILE"`; then
    # do something if True