The following is a part of my script where I want to echo some text to the local terminal if the condition fails in ssh.

/usr/bin/sshpass -p $PASSWORD /usr/bin/ssh -t  -o "StrictHostKeyChecking no" root@$IP -p $PORT '
    cd $PATH;
    [ ! -d temp ] && mkdir temp;
    for new_file in '${NEW_FILE[@]}'
        [  -f $new_file ] && mv -f $new_file temp/$new_file-'$DATE'
        DOWNLOAD=$(wget --no-check-certificate '$URL'/$new_file > /dev/null 2>&1)
        if [ '$?' -ne '0' ]; then
            mv temp/$new_file-'$DATE' '$PATH'/$new_file
            echo "$new_file download failed! please check and re-run the script"
            chmod +x $new_file

except echo remaining functionality works well ...

Let me know is it possible to echo from ssh to local terminal.


To selectively display an individual command as well as its output, you can use something like

sh -vc 'echo \"Some text\"'

although the nested quoting can start getting on your nerves pretty quickly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.