Is anyone using SSH command or SSH SHELL if so how do you use it.
Issues with SSH command : my .profile, .bashrc, .kshrc, PATH variable doesn't load as expected as a result when i run any script i see issues like No such file or directory if a script i run has relative path, JAVA_HOME is not picked up. If i set pty=true in SSH command everything loads up properly but response is terrible I'm getting everything (just printing everything on shell) from the SSH session unlike SSH command pty=false where i see only response, no proper return/exitcode. The only way to figure out if there was no error is stdErr is not empty and also exit executing script is there is sleep inside the script.
Issues with SSH SHELL : SHELL works pretty much similar to SSH command with pty=true with send and expect commands. I tried several expect regex (any suggestion is appreciated) and i cannot use expectEndsWith before I'm not sure what the prompt is going to be on all servers and i dont want to depend on that. My expect regex
the above expect works on some servers, doesnt work on some. expect works on a same server once and fails the other time.
My requirement is simple, there is a script on 10s of servers i have to SSH to that server and run the script. Script work absolutely fine when i run them on server but they fail when i use HPOO SSH SHELL and SSH command operations. Scripts may need password, scripts could have sleep in between, scripts may have relative path inside. How do i use HPOO to do this, nothing seems to be working for me.
- To get server/device prompt, I’ve used a subflow with the logic
- Ssh login (and keep seessionId fr all subsequent steps also in parent and brothers flows)
- Ssh shell, with command
and in results a scriptlet filter to find between a list of possible prompts (in my case was just between “#” and “>”)
- Some more ssh shell to prepare host for next steps
- If you need the exit code of a command or script inside a ssh shell, use “echo $?”, and parse later on results of operation 8not trivial but feasible)
- don’t assume env variables when doing ssh commands or shell, if you need them so a source of the proper file (like .<fullPathtobashrc or profile> or )
- I learnt it using Server Automation (which by the way is better oriented to execute a script on several hosts, as solve other problems like where is script centyrally stored and keep it ‘updated’ on all hosts)
- Send password in the middle of script is not trivial, in addition to detect the prompt, maybe will be a security issue is stored in cleartext in OO execution history, but if full output is obfuscated then difficult for troubleshooting when something fails. Much better is script can get password in a secure way (like reading a config file with proper permisions, or oher alternatives depending on which command needs it at the end)
Ramon has all good points. Also note that there are various types of ssh functions as well as v1 and v2
SSH Command = is just that for logging in running a command and not interacting with it (does not understand expect)
SSH Shell, Logon, Logoff = for interactive and understands expect
In additon there is a hidden readTimeout for longer running commands that you will want to add for example you are compiling source code and want to wait until it's finished in order to then do additional configurations.
Using the Logon -> pass sessionID to Shell you then will want to issue the command to ensure you have your environmental vars for example "send source /etc/environment" where you have an export XXX_HOME=/usr/local/<someapp>
As far as your regex goes, it's kind of difficult to automate something you don't know. I would suggest logging into each server to determine all the different combinations of prompts and then generate a regex that will cover them all.