BookmarkSubscribeRSS Feed
saspert
Pyrite | Level 9
Hi,
I am trying to accomplish a simple task using SAS & Unix server-
i) Create a shell script in a particular Unix directory which will have FTP commands
ii) Run this shell script from SAS to transfer the required files from server1 to server2.

Step i) is easily done using a data step+file statement+ put statements.
Stepii) is not working and I have tried 3 different ways -
a) X command
X 'sh /SASInt/.../ftp_script.sh &';
b) %macro sample;
%sysexec %str(sh /SASInt/.../ftp_script.sh &)'
c) filename results pipe "sh /SASInt/.../ftp_script.ksh &";

Even if I change the permissions to 777 for ftp_script.sh, it does not work.

Does anyone have suggestions?

Thanks.
9 REPLIES 9
Patrick
Opal | Level 21
What exactly is not working? What error do you get?

Can you execute your sh script from a command line window?

Is sh the default shell? You could give %systask a try as there you can explicitly define the shell.
DanielSantos
Barite | Level 11
Should work, nothing wrong with both methods you described.

Please give us more info about the error.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
LinusH
Tourmaline | Level 20
I suspect that the final task might be to read these files using SAS?
If this is the case you could give FILENAME FTP a try.

/Linus
Data never sleeps
saspert
Pyrite | Level 9
Hi guys,
I will reply to your questions -
Patrick:
1. It does not throw any errors. The log file shows it as executed but I dont see the file being transferred from server1 to server2. So, that means the ftp commands inside the shell script have not worked.
2.yes. I can execute this shell script from my unix command line. It works perfect.
3.I believe korn shell is the default shell. We also have bourne shell but I think the shell need not be changed?
Linus:
The final objective is to move text file/raw files from server1 to server2 where our group's SAS tools/instances are installed.

11 ODS HTML(ID=EGHTML) FILE=EGHTML ENCODING='utf-8' STYLE=EGDefault
11 ! STYLESHEET=(URL="file:///C:/Program%20Files/SAS/Shared%20Files/BIClientStyles/EGDefault.css")
11 ! ATTRIBUTES=("CODEBASE"="http://www2.sas.com/codebase/graph/v91/sasgraph.exe") NOGTITLE NOGFOOTNOTE GPATH=&sasworklocation
11 ! ;
12
13 %gaccessible;
14 X 'sh /SASInt/...../ftp_script.sh &'
14 ! ;
15
16
17 %LET _CLIENTTASKLABEL=;
18 %LET _EGTASKLABEL=;
;

The lines 11-13 and 15-18 are EG specific. They appear for all the codes executed in my EG. So,we can ignore them.

Thanks,
Raj.
Cynthia_sas
SAS Super FREQ
Hi:
Usually the X command is disabled for EG clients. It might be that your SAS administrators have done this at your installation. See these Tech Support Notes:
http://support.sas.com/kb/16/405.html
http://support.sas.com/kb/4/503.html

cynthia
SAS_user
Calcite | Level 5
what is the option XCMD value. If XCMD = NOXCMD, then you can not run X command.
Simplest way to do check:
proc options
option=XCMD;
quit;
abdullala
Calcite | Level 5
could it be that your working directory on the unix server (usually your /home) is different from the 'working directory' for the SAS program, which is defaulted to where the software is installed?
deleted_user
Not applicable
I think abdullala is on the right track. You gave the complete pathname of the script you wish to run; so, it runs. However, the working directory of the shell is the working directory SAS uses.
If the SAS working directory in not your home directory, and if the ftp commands in your script file do not give the complete pathnames of the files you wish to transfer, then the ftp process will not find the files. However, when you ran the script from the command line the current working directory was your home directory; hence, the files were found and the script succeeded.
Solutions:
1) put the complete pathnames of the files into your script.
2) put a cd command to your home directory (cd ~) into your SAS X command.
mich1
Obsidian | Level 7

Here is an example of Linux shell script used to sftp files created by a SAS program Robot Very Happy:

#!/bin/sh

echo "Ok, starting now..."

# You must put the system paths ahead of the paths added for SAS to include some cryptographic libraries

LD_LIBRARY_PATH=/usr/lib64:/lib64: $LD_LIBRARY_PATH

export LD_LIBRARY_PATH

sftp YOURUSER@SFTPSERVER << EOF

# Transfer all files using mput

mput /YOUR FOLDER ON SFTP SERVER/*

bye

In the corresponding SAS script you'd call it:

filename oscmd pipe "/FOLDER/SHELL_SCRIPT.sh 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
filename oscmd clear;
Bread Crumbs and Circuses for All

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 7513 views
  • 0 likes
  • 9 in conversation