I just want to check whether following code will work or not. It is like a validation

su -oracle "ssh  oracle@$MY_IP -o 'BatchMode=yes' -o 'ConnectionAttempts=1'"

echo "$returnCode"
 if [ $returnCode != 0 ]
  echo "Configuration is not valid"
  return 1;
  echo "Configuration is  valid"
  return 0;

When I run my script, it just gives me empty prompt. I can not enter to if statement. it seems script is trying to connect MY_IP.

How can I validate my statement without changing user and connecting to IP.

  • 1
    So you are trying to ensure you can still login without logging in? – Mike Pennington Jun 17 '12 at 22:54
  • I am not sure if it is really possible but yeah. – mibzer Jun 17 '12 at 22:55
  • What are the most probably events you are guarding against? Examples: Network failures, pam failures, sshd failures? – Mike Pennington Jun 17 '12 at 22:57
  • I am just trying to make a health check procedure, it will run everyday and report if ssh is not working... – mibzer Jun 17 '12 at 22:59
  • It works for me in Linux (are you using Solaris?). For my test I did: export MY_IP="" ; su mvaldez -c "ssh mvaldez@$MY_IP -o 'BatchMode=yes' -o 'ConnectionAttempts=1'" ; echo $? – MV. Jun 17 '12 at 23:27

The only test to ensure that you can reach the other machine and log in there is to log in. Run a command that does nothing.

su -c "ssh  oracle@$MY_IP -o 'BatchMode=yes' -o 'ConnectionAttempts=1' true" oracle
  • 1
    I'm not sure I see the need to su here... your ssh command is already using the oracle user – Mike Pennington Jun 17 '12 at 23:51
  • 2
    @MikePennington I left that in place. Presumably only the local oracle user has a private key that's authorized to log in as the remote oracle user, or there's some other authentication mechanism that requires oracle to run ssh. – Gilles Jun 18 '12 at 0:07

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.