我需要检查在远程主机上发布了一个transacions文件。今天12月31日没有发布交易代码。 我知道这是确定的。昨天有一个。然而,无论我使用哪个日期,30或31,返回码都是相同的。在bash中检查ssh remote命令的退出状态
我正在查看的是ssh的返回状态,我认为应该是远程执行命令的返回状态 我认为如果'ls -ltr'工作,'if语句'会以0退出和大于零的东西,如果'ls -ltr'没有 工作,则为false。我会认为'if'语句会查看shh的返回状态,这应该是远程执行的命令的返回状态 - 或者'ls -ltr'
我如何获得这个工作?
这是针对30 - 这是在远程主机上,并且是成功的
[email protected]:/scripts$ ssh -q -T [email protected] "ls -ltr /home/DropBox/transactions_20141230.csv"
-rw-r--r-- 1 rr_prd 2233047 Dec 31 07:26 /home/DropBox/transactions_20141230.csv
,这是对31没有报告还为31,所以它是不成功的
[email protected]:/scripts$ ssh -q -T [email protected] "ls -ltr /home/DropBox/transactions_20141231.csv"
/home/DropBox/transactions_20141231.csv not found
[email protected]:/scripts$
我不停地翻转与注释掉包括hashtag
[email protected]:/scripts$ ssh -q -T [email protected] "ls -ltr /home/DropBox/transactions_20141231.csv"
/home/DropBox/transactions_20141231.csv not found
[email protected]:/scripts$
#!/bin/bash
today=$(/bin/date +%Y%m%d)
#today="20141230"
echo $today
if ssh -q -T [email protected] "ls -ltr /home/DropBox/transactions_$today.csv" > /dev/null 2>&1 ;
then
echo "this worked"
else
echo "this did not work"
fi
但是日期 - 当我使用脚本两个日期 - 它是成功的,当为31,它真的应该返回“这并不工作”
[email protected]:/scripts$
[email protected]:/scripts$ vim offshore_check
[email protected]:/scripts$ ./offshore_check
20141230
this worked
[email protected]:/scripts$ vim offshore_check
[email protected]:/scripts$ ./offshore_check
20141231
this worked
[email protected]:/scripts$
[email protected]:/scripts$
它是一个较旧的离岸机器 - - SunOS 5.8 Generic_117350-35 - build-version 020 – capser