我只想检查以下代码是否有效。这就像一个验证
su -oracle "ssh oracle@$MY_IP -o 'BatchMode=yes' -o 'ConnectionAttempts=1'"
returnCode=$?
echo "$returnCode"
if [ $returnCode != 0 ]
then
echo "Configuration is not valid"
return 1;
else
echo "Configuration is valid"
return 0;
fi
Run Code Online (Sandbox Code Playgroud)
当我运行我的脚本时,它只给我一个空提示。我无法进入 if 语句。似乎脚本正在尝试连接 MY_IP。
如何在不更改用户和连接到 IP 的情况下验证我的语句。
确保您可以访问另一台机器并在那里登录的唯一测试是登录。运行一个什么都不做的命令。
su -c "ssh oracle@$MY_IP -o 'BatchMode=yes' -o 'ConnectionAttempts=1' true" oracle
Run Code Online (Sandbox Code Playgroud)