Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm relatively new to Unix or shell scripting (a total novice to speak the truth), here is the deal: I have BI software that runs on a remote UNIX server. Through SAS client on Windows i run some analytic and create some flat files that need to be automatically pushed to that UNIX server, that's no problem through the SAS X command to execute Unix commands on rsubmit, I upload the files throught FTP prompt however i want to use a "sh " command once I logged on the ftp server

ftp -nv << -EOF > /AutomatedReports/Flatfiles/log/sendInv.log
open biserver.myserver.com
user biuser pass1234
prompt
lcd  /container/AutomatedReports/KPI_Flatfiles/
cd  /container/AutomatedReports/apps/flatfiles
put kpi_new_inv.txt
put instock_trend.txt
quit

The code above is sent to UNIX, however when I include

sh edastart -x "EX test"

i get an error, I just want to know if Im doing something wrong so I can look for another way to do it. Any help, guidance or answer will be highly appreciated.

share|improve this question

migrated from stackoverflow.com Oct 27 '11 at 20:13

This question came from our site for professional and enthusiast programmers.

5 Answers 5

up vote 3 down vote accepted

No, you cannot start a program on a distant Unix server using FTP protocol (unless you use some bizarre extensions of it).

Why cannot you use ssh, that is copy the file to the distant Unix server using scp, and then login into that server using ssh.

share|improve this answer
1  
chiark.greenend.org.uk/~sgtatham/putty is a SSH client for Windows. –  Basile Starynkevitch Oct 27 '11 at 14:00
    
thanks, I do have putty installed on the computer, but the thing is I want to automate that process (the sas program runs on a scheduled task) so pretty much i do everything on it and the manually execute the remote script from putty which is precisely what I want to avoid, from SAS i can execute dos commands or batch files though, is there a way I could execute it if putty is isntalled on my machine? –  Rafael.IT Oct 27 '11 at 14:03

If you could execute arbitrary commands, that would be a gross security breach in the FTP server. FTP is a file transfer method only; for remote execution, turn to SSH instead.

share|improve this answer
    
I see... thanks for letting me know that.. is there a way to execute a shell script from windows (with authentication) without installing a third-party tool? –  Rafael.IT Oct 27 '11 at 13:57
    
@Rafael.IT: not that I know of. Grab Putty from chiark.greenend.org.uk/~sgtatham/putty and prey that an SSH server is installed on the remote host. While you're at it, switch from FTP to SFTP to get secure file transfer. –  larsmans Oct 27 '11 at 14:03
    
Thanks I do have putty on my machine, and the there is a SSH server on the remote host, thats how I execute the shell scripts remotely, but I need to automate this process... any suggestions? –  Rafael.IT Oct 27 '11 at 15:30

Do it over shell with putty like others said. If you need to automate the process why not set up a cron job and/or a trigger file?

share|improve this answer
    
cron jobs are on unix side, I have to automate it on windows side –  Rafael.IT Oct 27 '11 at 17:15

I do exactly this to execute a Hive query on a remote linux host, and have the results piped back to my SAS program. If there is no output from your SAS code then it's still a good idea to collect any STD output as you can then perform a check to make sure it all ran ok.

filename hive pipe 'C:\Progra~1\ICW\bin\ssh.exe server.name.local -l username -i c:\id_rsa " ls "' lrecl=80;

data x ;
  length line $80.;
  infile hive truncover;
  input @1 line $80.;
run;

The 3rd party executable I used can be found here:

http://www.itefix.no/i2/copssh

I generated an RSA key so I wouldn't have to supply my full credentials at each login but I'm sure you'll be able to figure that out, or just supply a regular username password as parameters...

Note that you could also execute the above remote command using the SAS 'X' command if you didn't want to pipe any results back.

Good luck R

share|improve this answer

Look into using TCL/Expect. The Expect module to TCL excels at automating console commands, including handling login prompts and passwords and ftp commands. With an Expect script, you can automate a complete ftp login session. Anything you can do manually you can do via Expect. You basically tell the shell what command to execute, and what prompt or response to "expect". What you expect can be specified as a hard coded value or as a regular expression. One example of using Expect is to script an automated test for logging into a Cisco router (userid/password), configuring the router, running some tests, verifying the results, then exiting out of the router.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.