Ahmet Karakaya
Ahmet Karakaya

Reputation: 10139

Check if remote file exists Linux

I have following script that is used to check if file exists in remote Linux machine. Although it works when directly invoked on console, it does gets me prompt asking password when this script is invoked in Java via Runtime->exec()

`ssh $HOSTNAME test -f $FILENAME`       
    result=$?
    result=0;
    if [ $result != "0" ]; then
        echo "$FILENAME is not found"
        exit 31;
    fi

I have also used the script adding user name as

`ssh root@HOSTNAME test -f $FILENAME

Upvotes: 1

Views: 1020

Answers (1)

jsurls
jsurls

Reputation: 375

You need to recheck your ssh keys and which user you're running as for Java. If the keys don't match then you'll be prompted for a user/password.

Upvotes: 2

Related Questions