# ksh script with Interactive ssh on remote server

**URL:** <https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922>\
**Category:** Shell Programming and Scripting\
**Created:** [September 8, 2011, 6:45am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922 "2011-09-08T06:45:55Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeevanm](https://community.unix.com/letter_avatar/jeevanm/32/5_5575768a8748004e209b776fc1b2916d.png) [@Jeevanm](https://community.unix.com/u/Jeevanm)\
**Post date:** [September 8, 2011, 6:45am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/1 "2011-09-08T06:45:55Z")

</div>

HI Unix Gurus,

I an stuck in an interesting issue, where I am trying to execute a script on remote server after ssh.  
The script on remote server is interactive,. Whenever it is called it hangs where it expects input from terminal and I have to terminate it.

I have searched through fourm and found -t -t is one option to use, but its not working in script, though it works from the shell prompt for execution of single command.

Can any one help me with this please.

Below are the brief contents of the KSH Script.

```nohighlight
#!/bin/ksh
ip=192.168.113.14
hst=rhel_server
 
flg=0
 
if [${flg} -eq 0]
then
ssh -o IdentityFile=/root/.ssh/id_dsa -t -t root@${ip} << EOF
ksh /remote_script/server_install_soft.ksh ## Interactive Script
rm /tmp/log/old_log.log
EOF
fi
exit

```

---

<div class="post-metadata">

**Author:** ![psshah](https://community.unix.com/letter_avatar/psshah/32/5_5575768a8748004e209b776fc1b2916d.png) [@psshah](https://community.unix.com/u/psshah)\
**Post date:** [September 8, 2011, 6:51am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/2 "2011-09-08T06:51:11Z")

</div>

What does your script /remote\_script/server\_install\_soft.ksh ?  
You may need to automate your script to avoid any interactive input.  
When you are running ksh, it is waiting for input in that session, not in your ssh session.

---

<div class="post-metadata">

**Author:** ![Jeevanm](https://community.unix.com/letter_avatar/jeevanm/32/5_5575768a8748004e209b776fc1b2916d.png) [@Jeevanm](https://community.unix.com/u/Jeevanm)\
**Post date:** [September 13, 2011, 1:07am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/3 "2011-09-13T01:07:16Z")

</div>

HI PSShah,

My requirement is to have /remote\_script/server\_install\_soft.ksh script intractive.  
This script takes inputs from screen like select option 1,2 3 or press enter to continue etc.

As you said its waiting for input in that session and not in my session,  
I need to know is it possible to supply input from my current shell.

Thanks,  
Jivan

---

<div class="post-metadata">

**Author:** ![Chubler\_XL](https://community.unix.com/user_avatar/community.unix.com/chubler_xl/32/2077_2.png) [@Chubler\_XL](https://community.unix.com/u/Chubler_XL)\
**Post date:** [September 13, 2011, 1:14am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/4 "2011-09-13T01:14:28Z")

</div>

Try like this:

```nohighlight
#!/bin/ksh
ip=192.168.113.14
hst=rhel_server
 
flg=0
 
if [${flg} -eq 0]
then
    ssh -o IdentityFile=/root/.ssh/id_dsa -t -t root@${ip} '
        ksh /remote_script/server_install_soft.ksh ## Interactive Script
        rm /tmp/log/old_log.log '
fi
exit

```

---

<div class="post-metadata">

**Author:** ![Jeevanm](https://community.unix.com/letter_avatar/jeevanm/32/5_5575768a8748004e209b776fc1b2916d.png) [@Jeevanm](https://community.unix.com/u/Jeevanm)\
**Post date:** [September 16, 2011, 5:03am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/5 "2011-09-16T05:03:20Z")

</div>

Hi Chubler\_XL,

The Result is same .. the Script hangs,  
Any other options is available

---

<div class="post-metadata">

**Author:** ![Jeevanm](https://community.unix.com/letter_avatar/jeevanm/32/5_5575768a8748004e209b776fc1b2916d.png) [@Jeevanm](https://community.unix.com/u/Jeevanm)\
**Post date:** [September 27, 2011, 1:55am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/6 "2011-09-27T01:55:00Z")

</div>

Hi All Gurus,

I am still unable to solve this problem and expert advise will really help.

Thanks.

---

<div class="post-metadata">

**Author:** ![ahamed101](https://community.unix.com/user_avatar/community.unix.com/ahamed101/32/1118_2.png) [@ahamed101](https://community.unix.com/u/ahamed101)\
**Post date:** [September 27, 2011, 2:27am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/7 "2011-09-27T02:27:15Z")

</div>

```nohighlight
[apple@bt ~/aen]cat run
#!/bin/bash
echo "Please enter an integer value : "
read var
echo "Entered value is $var"
 
[apple@bt ~/aen]ssh apple@192.168.1.3 "echo 123 | /home2/apple/aen/run"
Please enter an integer value :
Entered value is 123

```

Something like this?

--ahamed

---

<div class="post-metadata">

**Author:** ![ygemici](https://community.unix.com/letter_avatar/ygemici/32/5_5575768a8748004e209b776fc1b2916d.png) [@ygemici](https://community.unix.com/u/ygemici)\
**Post date:** [September 27, 2011, 4:30am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/8 "2011-09-27T04:30:56Z")

</div>

> [@jeevanm](#):
>
> Hi All Gurus,
> 
> I am still unable to solve this problem and expert advise will really help.
> 
> Thanks.

try this

```plaintext
ssh -o IdentityFile=/root/.ssh/id_dsa root@${ip} 'ksh /remote_script/server_install_soft.ksh;rm /tmp/log/old_log.log'

```

---

<div class="post-metadata">

**Author:** ![Jeevanm](https://community.unix.com/letter_avatar/jeevanm/32/5_5575768a8748004e209b776fc1b2916d.png) [@Jeevanm](https://community.unix.com/u/Jeevanm)\
**Post date:** [September 27, 2011, 6:57am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/9 "2011-09-27T06:57:52Z")

</div>

Nope, this I have tried but it does not work,

I have to execute the script /remote\_script/server\_install\_soft.ksh :wall:on remote server from my current shell. As explained in detail in the beginning of the thread.

Thanks

---

<div class="post-metadata">

**Author:** ![ygemici](https://community.unix.com/letter_avatar/ygemici/32/5_5575768a8748004e209b776fc1b2916d.png) [@ygemici](https://community.unix.com/u/ygemici)\
**Post date:** [September 27, 2011, 7:04am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/10 "2011-09-27T07:04:02Z")

</div>

what is the output after this?

```nohighlight
# ksh -x yourscript

```

---

<div class="post-metadata">

**Author:** ![Jeevanm](https://community.unix.com/letter_avatar/jeevanm/32/5_5575768a8748004e209b776fc1b2916d.png) [@Jeevanm](https://community.unix.com/u/Jeevanm)\
**Post date:** [January 25, 2012, 5:37am UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/11 "2012-01-25T05:37:38Z")

</div>

Dear friend,ygemici  
Could you please explain why you need "-x" (execution output) here?  
The question is how to execute an interactive script from server A on server B.  
As far as I know The "-x" is irrelevant here. Request you to go through the question once again and correct me if I am wrong.

The question is still open for all and not yet resolved.

The alternate I am using is to send feedback why ssh from server B to server A and execute scripts there, unfortunately its very vary complex 😕☹

---

<div class="post-metadata">

**Author:** ![ygemici](https://community.unix.com/letter_avatar/ygemici/32/5_5575768a8748004e209b776fc1b2916d.png) [@ygemici](https://community.unix.com/u/ygemici)\
**Post date:** [January 25, 2012, 2:56pm UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/12 "2012-01-25T14:56:25Z")

</div>

> [@jeevanm](#):
>
> Dear friend,ygemici  
> Could you please explain why you need "-x" (execution output) here?  
> The question is how to execute an interactive script from server A on server B.  
> As far as I know The "-x" is irrelevant here. Request you to go through the question once again and correct me if I am wrong.
> 
> The question is still open for all and not yet resolved.
> 
> The alternate I am using is to send feedback why ssh from server B to server A and execute scripts there, unfortunately its very vary complex 😕☹

I'm trying to figure out the cause of the hangup.  
debugging,everytime gives an idea.  
now can you write the contents of script?

```plaintext
# cat server_install_soft.ksh

```

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/5_5575768a8748004e209b776fc1b2916d.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [January 25, 2012, 5:25pm UTC](https://community.unix.com/t/ksh-script-with-interactive-ssh-on-remote-server/294922/13 "2012-01-25T17:25:14Z")

</div>

Post #7 is about as near as you are going to get. It provides typeahead to the interactive program. This usually works better with the "-n" switch to the remote Shell program. The remote shell approach is best done with a custom script on the remote computer.

If you want to work interactively with a remote computer you need to login properly, do your typing, and then logout. There may workarounds for repetitive tasks but don't bet on it.

I'm not still clear what you are actually trying to do. All we have to work on is a solution which does not work. We need to see the problem.
