Checking the exit status of a ssh remote command in bash

前端 未结 3 724
轻奢々
轻奢々 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:33

    The "if" construct that you're using should work, and it does work for me:

    $ if ssh -q -T localhost "ls -ltr /does/not/exist"; then echo succeeded; else echo failed; fi
    Password:
    ls: /does/not/exist: No such file or directory
    failed
    

    I notice that the error printed by your ls program is worded differently than the error that I got (and I tried two different systems). "file not found" in your case, "ls: file: No such file or directory" in mine. My suspicion is that the ls command which you're invoking here isn't the typical modern Unix command. You may be running a nonstandard version, a non-Unix version, or something very old, and it may not actually be exiting with a non-zero exit code for this particular error.

提交回复
热议问题