- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 10-15-2009 05:41 PM
(8831 views)
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Please give us more info about the error.
Cheers from Portugal.
Daniel Santos @ www.cgd.pt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
If this is the case you could give FILENAME FTP a try.
/Linus
Data never sleeps
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Simplest way to do check:
proc options
option=XCMD;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here is an example of Linux shell script used to sftp files created by a SAS program :
#!/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