java - Calling a shell script using SSH exec channel, but it ignores calls to other shell scripts -
i managing execute shell script on remote server using jsch exec using helpful examples provided here. can see echoes being returned script , exit status @ end 0 - looks @ first glance.
however, problem script calls out other scripts, , these appear ignored, skipped over.
the script calls other scripts directly. i.e. first line of script like:
script_two.sh
could advise of way overcome this? did start "shell" channel instead of "exec", may tricky in case because before giving user access system, server presents form fill in (name, number, why logging in, etc) - haven't yet been able to programmatically fill in , submit form, stick exec if possible.
i new this, help/advice welcome!
code snippet below. said, appears work, sh script represented "scriptfilename" int code calls other sh scripts, , these not executed.
many in advance help, j
jsch jsch = new jsch(); jsch.setconfig(filetransferconstants.strict_host_key_checking, "no"); session session = jsch.getsession(username, hostipaddress, port); session.setpassword(password); session.connect(); //create execution channel on session channelexec channelexec = (channelexec)session.openchannel("exec"); channelexec.setcommand(scriptfilename); channelexec.connect();
i assume script looks like:
script_one.sh script_two.sh
i.e. script relies on .
(the current path) being in path
environment variable, not default.
so script ever work, .
has added path
in startup script. it's quite probable addition occurs (probably unintentionally incorrectly) interactive sessions. because addition done in startup script executed (sourced) the interactive sessions only.
the "exec" channel in jsch (rightfully) not allocate pseudo terminal (pty) session. consequence different set of startup scripts (might be) sourced than, when login ssh client. and/or different branches in scripts taken, based on absence/presence of term
environment variable. environment might differ interactive session use ssh client.
solutions (in preferred order):
correct script not rely on non-default settings of having
.
inpath
. call sub-scripts explicit path:./script_one.sh ./script_two.sh
correct startup scripts add
.
path
unconditionally (even non-interactive sessions).(not recommended) force pseudo terminal allocation "exec" channel using
.setpty
method:channel channel=session.openchannel("exec"); ((channelexec)channel).setpty(true);
using pseudo terminal automate command execution can bring nasty side effects. see example is there simple way rid of junk values come when ssh using python's paramiko library , fetch output cli of remote machine?
see related question shell ping command source option failing when executed using jsch setcommand.
Comments
Post a Comment