1

I have the below script that works fine when run locally

cat /tmp/input.sh

                echo -n ">> "
                read env
                exit;

I get the command prompt when i run as below.

$/tmp/input.sh | echo "whatever"
$

All good so far. The problem occurs when i run this script via ssh

ssh wladmin@myhost /tmp/input.sh | echo "whatever"

This system is for the use by authorized users only. All data contained
on all systems is owned by the company and may be monitored, intercepted,
recorded, read, copied, or captured in any manner and disclosed in any
manner, by authorized company personnel. Users (authorized or unauthorized)
have no explicit or implicit expectation of privacy. Unauthorized or improper
use of this system may result in administrative, disciplinary action, civil
and criminal penalties. Use of this system by any user, authorized or
unauthorized, constitutes express consent to this monitoring, interception,
recording, reading, copying, or capturing and disclosure.

IF YOU DO NOT CONSENT, LOG OFF NOW.

##################################################################
# *** This Server is using Centrify                          *** #
# *** Remember to use your Active Directory account          *** #
# ***    password when logging in                            *** #
##################################################################

As you see i expected control on the command prompt terminal i.e $ but unless i press Crtl + C or others i do not get the command prompt to type further.

I tried ssh -T option but that did not help.

Can you suggest what needs to be done?

1 Answer 1

0

The echo "whatever" is killing the script at the echo -n ">> " line, since it is not accepting any input coming from the script - therefore the read env never happens. I do not see why you would be doing |echo like that but carrying on regardless - When you do the ssh, only the input.sh script gets run remotely - and it does not "know" that text to stdout will be rejected. To get the same effect, run everything remotely, i.e. quote or escape the |

ssh wladmin@myhost /tmp/input.sh \| echo "whatever"
4
  • The purpose of | echo is to feed input to the read env. I don't know if there is a better way to do that?
    – Ashar
    Sep 20, 2022 at 14:45
  • its using ksh shell. i tried your solution but i get the below error. + exec /usr/share/centrifydc/libexec/ssh wladmin@myhost '|' echo whatever ksh: syntax error at line 1: '| unexpected `
    – Ashar
    Sep 20, 2022 at 15:00
  • It's a typo - you dropped the /tmp/input.sh script Sep 21, 2022 at 7:30
  • 1
    To feed the echo to the script, it needs to be in front, and then the local or remote won't matter either. So echo "whatever" | ssh wladmin@myhost /tmp/input.sh Sep 21, 2022 at 7:31

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.