1

I'm trying to SSH from a mac osx machine to a solaris based machine and pass some commands but I'm not sure the best way to do it and am running into all sorts of issues using the different methods I've found online. Right now the closest thing I have to working is:

fraudcheck.sh

#!/bin/sh
#
SUPNODE="X.X.X.X"
ssh -i /Users/jessebutryn/.ssh/Jesse_id_rsa root@$SUPNODE < /Users/jessebutryn/Documents/scripts/incomplete/fraudcommands.sh

fraudcommands.sh

#!/bin/sh
#
source /root/toolbox/toolbox
jbutryn
fraud 1

When I run these commands manually the output is as follows:

joyentmac2252:~ jessebutryn$ ssh root@X.X.X.X
[root@sup-jpc-west1 ~]# source /root/toolbox/toolbox
Enter your JPC Headnode username: jbutryn
Toolbox - Version 4.4.6 - It's Wednesday, this must be Devon (20161116)
---- Recent Changes ----

Replaced sdc-ldap/ufds with OpenLDAP client
vm/vmi now shows Swap
Moved creds to environment
Added random element to disabler string
fraud() speed up
Added over() for PD overrides
Added RAM to vms_by_pkg / fraud
Added dates to cust()
Big speed up for cust_vms(). You are welcome.

------------------------
[root@sup-jpc-west1 ~]# fraud 1
2017-06-29|2017-06-30
DC      ALIAS         UUID                                  RAM    BILLING_ID                            OWNER                                 CREATED
sw_1    SRADB02PRJOY  f70b0642-020c-cd72-d644-e0453ccd0e56  65536  14bc8e86-d0f8-11e5-a148-b39af8e5cb7b  bc1e2a34-e6fd-c421-d362-aeccb09eb9a4  2017-06-30T20:29:36.853Z
...

However when I run the script it gives the following output:

joyentmac2252:~ jessebutryn$ ~/Documents/scripts/incomplete/fraudcheck.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
Toolbox - Version 4.4.6 - It's Wednesday, this must be Devon (20161116)
---- Recent Changes ----

Replaced sdc-ldap/ufds with OpenLDAP client
vm/vmi now shows Swap
Moved creds to environment
Added random element to disabler string
fraud() speed up
Added over() for PD overrides
Added RAM to vms_by_pkg / fraud
Added dates to cust()
Big speed up for cust_vms(). You are welcome.

------------------------
/root/toolbox/toolbox: line 1888: [: =: unary operator expected
2017-06-29|2017-06-30
DC  ALIAS  UUID  RAM  BILLING_ID  OWNER  CREATED

Below is line 1888 in the toolbox script and I'm not even sure what it's purpose is but I know I don't match that user:

[root@sup-jpc-west1 ~]# sed '1888!d' sup-toolbox/toolbox
if [ $(who am i | /usr/bin/cut -d' ' -f 1) = "some_user" ]; then

I've tried all sorts of solutions for passing the commands through including:

echo "jbutryn" | ssh -i ...

ssh -i ... "
jbutryn
fraud 1
"

I've tried to echo and read the commands in the fraudcommands script. I'm fairly new to all of this so any help is appreciated. Thanks!

2

You are getting the [: =: unary operator expected error because the who am i command on the left side $(who am i | ...) is not returning any text, so therefore you should always put such fields/variables/etc. in quotes.

The reason who am i is returning no text, is because it gives you the information about the terminal (which only exists if you run it "manually"). Unfortunately ssh is not starting a "real/full" terminal session if you running a command (so called non-interactive session). You should try replacing it with e.g. $USER, which is even more efficient (variable access is way faster than starting a new program):

if [ "$USER" = "some_user" ]; then

As a workaround you could run it with ssh -t <script>, which will allocate a pseudo-terminal, making who am i work again.

  • You're welcome, if you find the information useful you can upvote answers and comments with the little up-arrow on the left side next to it. For a workaround see the updated answer. – Folfy Jun 30 '17 at 22:34
  • No problem, and you should have the reputation now ;) – Folfy Jun 30 '17 at 22:40

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.