DATA Step, Macro, Functions and more

ssh in X command in SAS code

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

ssh in X command in SAS code

I am trying to use ssh unix command in X command in  a SAS code , but it is not working, ssh is not able to connect to rmeote server

 

x  'ssh remote_server "cd dir1 ; mkdir abc"';

 

Anyone could help would be great


Accepted Solutions
Solution
‎06-20-2016 05:49 AM
Super User
Super User
Posts: 7,958

Re: ssh in X command in SAS code

It means the place where the SAS program executes does not have the authentication to access the host.  Perhaps your SAS is on a network drive?  If so that network drive would need to have the host information setup on it.  Speak to your IT group, they will be able to do that.

View solution in original post


All Replies
Super Contributor
Posts: 441

Re: ssh in X command in SAS code

Have you tried this at a shell prompt? The first test would be to execute this command on the machine where your SAS code runs and as the user that runs the code. If you can connect bu get prompts than deal with those first. SSH should not prompt for password, passphrase or display some logon banner text. Use of a SSH key is in order. Only then you can hope it will work from SAS.

 

For further ideas I would like to see your error messages.

 

Regards,

- Jan.

New Contributor
Posts: 4

Re: ssh in X command in SAS code

Posted in reply to jklaverstijn

Hi , I tried the ssh command on unix shell directly and it is working fine there , so this means I do have a succesful ssh set up but when i try the same command from SAS thru X , it does not work and in sas log it do not shows any ERROR messages too. Below is thecommand which i submitted on shell , apspt0152 is the remote server (password keys already set up) , and it is able to craete dir abc on apspt0152

 

ssh apspt0152 "cd /aalfmodl/Devki ; mkdir abc"

*******************************************************************************

* *

* This is a private computer system containing confidential information. *

* Any unauthorized attempt to access or use this computer system or any *

* information on it by employees or other persons may result in termination *

* of employment, civil fines, and criminal penalties. This system must be *

* used for authorized business purposes only. *

* *

*******************************************************************************

!!! This system is configured with LDAP authentication !!!

 

Super User
Super User
Posts: 7,958

Re: ssh in X command in SAS code

And does it work when run directly in your operating system?  To be honest I don't see that command working as your not connected to anything or providing any connection details, but I am not a Unix user so don't know the application, but the examples I see online show:

ssh username@username.suso.org

 

as connection, then you pass other commands in.  The answer is anyways, get the commands working at the command prompt then copy them into your SAS program.

New Contributor
Posts: 4

Re: ssh in X command in SAS code

hi

 

I am using this command  where remote server is apspt0152 which is the actual hostname. the command is working fine at the shell but not is SAS code thru X

x 'ssh apspt0152 "cd /aalfmodl/Devki ; mkdir abc"';

 

 

Super User
Super User
Posts: 7,958

Re: ssh in X command in SAS code

You might want to read in the OS output to a dataset to see the results:

 

filname abc pipe 'ssh apspt0152 "cd /aalfmodl/Devki ; mkdir abc"';

data temp;

  length res $2000;

  infile abc dlm="¬";

  input res $;

run;

 

Or simliar, you should then see the txt from the OS populated in a dataset.  I would guess that your SAS system doesn't have the priviledges needed, i.e. SAS might be installed on a server or something.

Super User
Super User
Posts: 7,050

Re: ssh in X command in SAS code

Execute the operating system commands using a PIPE. Then you can read the messages that it sends.

 

data _null_;
  infile 'ssh remote_server "cd dir1 ; mkdir abc"' pipe;
  input;
  put _infile_;
run;

Most likely you have either entered the hostname or path names incorrectly.  But it might be that the process that is running your SAS program does not have permission to SSH to the remote or needs to supply a password.

New Contributor
Posts: 4

Re: ssh in X command in SAS code

Hi Tired this :
data _null_;
infile 'ssh apspt0152 "cd /aalfmodl/Devki; mkdir thrupipe"' pipe;
input;
put _infile_;
run;

and in the sas log :
NOTE: AUTOEXEC processing completed.

1 data _null_;
2 infile 'ssh apspt0152 "cd /aalfmodl/Devki; mkdir thrupipe"' pipe;
3 input;
4 put _infile_;
5 run;

NOTE: The infile 'ssh apspt0152 "cd /aalfmodl/Devki; mkdir thrupipe"' is:
Pipe command="ssh apspt0152 "cd /aalfmodl/Devki; mkdir thrupipe""

Host key verification failed.
2 The SAS System 08:00 Tuesday, June 14, 2016

NOTE: 1 record was read from the infile 'ssh apspt0152 "cd /aalfmodl/Devki; mkdir thrupipe"'.
The minimum record length was 29.
The maximum record length was 29.
NOTE: DATA statement used (Total process time):
real time 0.36 seconds
cpu time 0.00 seconds

I am not sure what does this means here "Host key verification failed. "
Solution
‎06-20-2016 05:49 AM
Super User
Super User
Posts: 7,958

Re: ssh in X command in SAS code

It means the place where the SAS program executes does not have the authentication to access the host.  Perhaps your SAS is on a network drive?  If so that network drive would need to have the host information setup on it.  Speak to your IT group, they will be able to do that.

New Contributor
Posts: 4

Re: ssh in X command in SAS code

The unicx ID which I was using did not had proper access to the SAS server , had to work with unix and IT admins for the same and then the pipe method using SSH command was working perfectly.. Thanks guyz for all the help ...
Super Contributor
Posts: 441

Re: ssh in X command in SAS code

Hi @devki

 

A few potential causes you may want to check:

 

  • Try adding the -o 'StrictHostKeyChecking=no' to the ssh command. Also add -o 'LogLevel quiet' to suppress the welcome banner
  • Check to see if selinux, if enabled, is blocking you. I have seen this happening where on the shell it works and from scripting not: 
grep AVC /var/log/audit/audit.log

You may need to ask your sysadmin to help on this, especially to resolve it if selinux is indeed at play. There are some sdelinux booleans that deterrmine how ssh behaves. Do this on the target server.

 

Furthermore make absolutely certain that your SAS code executes on the same host and same user as your shell tests. The client/server approach of Enterprise Guide or any use of grid servers may make this actually fuzzy.

 

Regards, Jan.

Valued Guide
Posts: 505

Re: ssh in X command in SAS code

Posted in reply to jklaverstijn

Hi Team

 

  I am a little out of my element here, but depending on your  access privileges you might try

 

  'sudo ssh apspt0152 "cd /aalfmodl/Devki; mkdir thrupipe""

 

My understanding is that some commands require higher access priviledges and the DBA can give you 'super user do" authority for certain unix commands.

 

However it will prompt for your password. I have used this with 'full' SAS, but Ihave my doubts that it will work with EG, UE or SAS Studio.

 

Also you may need to know your 'lockdown' state. 

Super User
Posts: 19,815

Re: ssh in X command in SAS code

Why do you need to create this folder? Can you use dcreate() function if SAS can see the server?

Super Contributor
Posts: 266

Re: ssh in X command in SAS code

Super Contributor
Posts: 266

Re: ssh in X command in SAS code

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 14 replies
  • 1008 views
  • 3 likes
  • 7 in conversation