EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Read command in shell script

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#22410
Posted: 11/08/2012 23:40:15
by Robert Yarbrough (Basic support level)
Joined: 11/08/2012
Posts: 4

I'm evaluating the SSH functionality in the SecureBlackBox product. So far it's looking good. I'm having a problem with a read command inside of a shell script. I'm looking to get user input, but when passing the value in similarly to the way the example SSH application works, it doesn't seem to get the value to the script.

Is there something I might be missing, or do I need to send the command in a different way? Any help would be appreciated.

Thanks!
#22412
Posted: 11/09/2012 00:47:25
by Ken Ivanov (EldoS Corp.)

Hello Robert,

Thank you for your interest in our products.

Could you please share your SSHBlackbox-related code with us so that we could have a look into?
#22421
Posted: 11/09/2012 09:00:25
by Robert Yarbrough (Basic support level)
Joined: 11/08/2012
Posts: 4

Quote
Innokentiy Ivanov wrote:
Hello Robert,

Thank you for your interest in our products.

Could you please share your SSHBlackbox-related code with us so that we could have a look into?


Sure, here is the function I use to send the command...

Code
      public void Send(string Data)
      {
         Application.DoEvents();
         byte[] encoded = System.Text.Encoding.UTF8.GetBytes(Data + "\x0d\x0a");
         client.SendData(encoded, encoded.Length);
         Application.DoEvents();
      }


This is called from a button click event and the data is straight from a textbox.

Here is a small piece of the linux script. As you can see, I'm trying to read in a value and then check to make sure something was entered. When coming from my code above, I don't think it's getting anything.

Code
read restore_name
if [ "$restore_name" == "" ]
then
        exit
fi


Thanks in advance for the help :-)

Robert
#22424
Posted: 11/09/2012 09:54:15
by Ken Ivanov (EldoS Corp.)

Thank you for the details.

1) Does the script work with one of the sample applications (SimpleSSHDemo for instance)?

2) Are you using the component in shell or command mode?

3) Does your code work with simple commands requiring no input from user (e.g. ls)?
#22428
Posted: 11/09/2012 19:22:54
by Robert Yarbrough (Basic support level)
Joined: 11/08/2012
Posts: 4

Quote
Innokentiy Ivanov wrote:
Thank you for the details.

1) Does the script work with one of the sample applications (SimpleSSHDemo for instance)?

No, it does not, nor does running ". oraenv" work at pulling in input.

Quote
2) Are you using the component in shell or command mode?

I'm not sure how to check this... it's whatever mode the sample application is in. I took a quick look through the client object properties, but didn't see what would tell me what mode it is in.

Quote
3) Does your code work with simple commands requiring no input from user (e.g. ls)?


Yes, it works fine for ordinary commands.
#22440
Posted: 11/12/2012 00:37:02
by Ken Ivanov (EldoS Corp.)

Robert,

Thank you for the answers. Now we have some information to play with.

To re-formulate the second question of mine, you can run a command with TElSimpleSSHClient in three ways:

1) open the shell and then send the name of the command to the shell with the SendData() call (thus emulating a user who types a command and submits it with CR/LF). This is the default behaviour of the component.

2) Assign the command to the Command (Commands) property of the component. A command tunnel, instead of a shell, will be opened in this case, and all the data sent via SendData will be directed to the command.

3) Run ExecuteCommand() to run a simple one-input-one-output command.

Which exactly method are you using in your application?
#22454
Posted: 11/12/2012 15:07:16
by Robert Yarbrough (Basic support level)
Joined: 11/08/2012
Posts: 4

I'm using method 1 from what I can tell. I tried just using the ExecuteCommand() method, but it appears that it must have some sort of implicit connect functionality because I get an exception stating that the client is already connected.

I'm thinking the execute command functionality is meant for sending a single command then immediately disconnected, which would not work for me as I am running a script which is waiting for user input.

I tried using the SentText() method, but it didn't seem to do anything.
#22457
Posted: 11/12/2012 23:48:59
by Ken Ivanov (EldoS Corp.)

You are correct - ExecuteCommand() opens a connection and performs all send/receive functions internally, so you do not need to run them explicitly in this case. Still, this approach seems to hardly suit your task, as it is only applicable for simple one-send-one-get environments.

OK, could you please try to assign the path to your script to the Command property and try to communicate with the script in this mode? Note that when the Open() method exits, the command is already launched (so whatever you are sending goes directly to the script).

Depending on the configuration of the system, you might need to run a shell executable instead of a script itself; in this case you would normally pass the name of the script as a parameter.
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

Topic viewed 1370 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!