Trigger UNIX Script from SAP

Hi..
The requirement is as follows :
SAP drops a file into a folder and triggers a UNIX script using a File Port partner destination.
Unix script will perform a secure copy to the Webmethods server.  If a Unix script error occurs, an Rfc function will be called to send an error notification to a particular contact  person.
Can anyone help me how is the unix script triggered from SAP ?
Thanks in advance

You can execute this sample code:
Data: unix_cmd(50).
unix_cmd = 'chmod 664 /sapdata/DEV/home/travelers'.
translate   unix_cmd to lower case.
call 'SYSTEM' id 'COMMAND' field unix_cmd.
write: / sy-subrc.
OR
Create and run a UNIX command programmatically
The destination must be set up and configured from tcode SM59
                                              see note OSS 63930
rfcexec, this service must be started from UNIX
UX syntax to start service:
       rfcexec -aUNIX_COMMAND -g sap01 -x sapgw00 &
       rfcexec        - program, /sapmnt/DEV/exe
       UNIX_COMMAND   - program ID from SM59, case sensitive
       sap01          - AP_Gateway_hostname
       sapgw00        - Gateway_Service
Transaction SMGW, monitor the gateway (Goto/Logged on clients)
*Number LU name  TP Name        Syst.type    Host name  Host address
   0  sap01    sapgw00        LOCAL_R3       sap01    10.1.193.50
233  sap01    UNIX_COMMAND   REGISTER_TP    sap01    10.1.193.50
Could replace this unsupported SAP syntax,         Call 'SYSTEM'
*data: begin of tabl occurs 0,
line(200),
*end of tabl.
*call 'SYSTEM' id 'COMMAND' field comm
             id 'TAB' field tabl-sys.
data: command(256).
data : begin of ret occurs 10,           " results of unix command
        text(80),
      end of ret .
data: i_connected_systems type table of gwy_system.
data: w_connected_systems type  gwy_system.
data: w_message(80).
parameter: p_junk(4) default 'Junk'.
start-of-selection.
call function 'GWY_READ_CONNECTED_SYSTEMS'
EXPORTING
  GWHOST                          =
  GWSERV                          =
  DISCONNECT                      =
  tables
    connected_systems               = i_connected_systems
EXCEPTIONS
  GWY_UNKNOWN_OPCODE              = 1
  GWY_COMMUNICATION_FAILURE       = 2
  GWY_GET_TAB_FAILED              = 3
  GWY_NEWLINE_FAILED              = 4
  GWY_TABLEN_TOO_SHORT            = 5
  GWY_GET_OPCODE_FAILED           = 6
  GWY_GET_GWHOST_FAILED           = 7
  GWY_GET_GWSERV_FAILED           = 8
  GWY_MONITOR_DISABLED            = 9
  OTHERS                          = 10
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
read table i_connected_systems into w_connected_systems
           with key tpname = 'UNIX_COMMAND'.
if sy-subrc ne 0.
  perform display_error_messages.
  stop.
endif.
*COMMAND = 'ls '.                           " command
*COMMAND = 'ls -lt'.       " command, newest at top
command = 'ls -osra'.
call function 'RFC_REMOTE_PIPE'
DESTINATION 'SERVER_EXEC'
  destination 'UNIX_COMMAND'
  exporting
    command  =   command
    read     =   'X'
  tables
    pipedata =   ret.
loop at ret.
  write ret.
endloop.
end-of-selection.
*&      Form  Display_error_messages
form display_error_messages .
  data: begin of listtab occurs 0,
        field(80),
        end of listtab.
  listtab-field = 'Program UNIX_COMMAND is not registered.'.
  append listtab.
  listtab-field = 'Tell Basis person about the error'.
  append listtab.
  listtab-field = ' '.
  append listtab.
  listtab-field = 'UX syntax to start service: '.
  append listtab.
  listtab-field = 'rfcexec -aUNIX_COMMAND -g sap01 -x sapgw00'.
  append listtab.
  listtab-field = ' '.
  append listtab.
  listtab-field = 'Program  aborted,'.
  listtab-field+19 = sy-cprog.
  append listtab.
  call function 'POPUP_WITH_TABLE_DISPLAY_OK'
    exporting
      endpos_col         =     70
      endpos_row         =     20
      startpos_col       =     10
      startpos_row       =     10
      titletext          =    'Registered program error'
  IMPORTING
    CHOISE             =
    tables
      valuetab           =  listtab
  EXCEPTIONS
    BREAK_OFF          = 1
    OTHERS             = 2
  if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
endform.                    " Display_error_messages
Bruce

Similar Messages

  • Executing Unix scripts from a stored procedure

    From the sql*plus windows, I am able to execute the host command and '!sh' commands; but I need to ececute Unix scripts from a stored procedure. Hoe can I do this? Where can I get good documentation on this? Any help would be greatly appreciated!
    Thanks..

    Hi,
    U can use external procedure ( newly added feature in 8.0.3 onwards) and call any shared library. From shared library u can execute it.
    One sql command is there HOST(' '). U can run a OS command. But u can not use it in PL/SQL.
    U can call pls sql from shell !!!!!..
    Thanks...
    Boby Jose

  • How to Trigger an IDOC from SAP R/3 to two systems at a time

    Hi experts,
    Can any one please tell me How to Trigger an IDOC from SAP R/3 to two XI systems at a time.
    My current production R/3 system sends a DELVRY03 IDOC to Production XI system ( Name : XIP) .
    I would like to route the same IDOC from production R/3 system to my Quality XI System ( Name XIQ) .
    Problem is production R/3 system triggers an IDOC once. We need to write a logic to route the same to two different systems
    Can any one tell me how can we do that ?
    Regards
    Ram.

    Hello Ram,
    Do you have connectivity between your production & XIQ?
    What does "connectivity" mean?
    1. RFC destination is maintained.
    2. Port defined for the RFC destination.
    If no, create these. (Search in SDN for details).
    If yes, proceed:
    1. Define the logical system for XIQ.(BD54)
    2. Define the same as your partner profile. (WE20). Add the message type SYNCH with the port for XIQ.(This is imp)
    3. Create a distribution model view with sender as "your production" & receiver as XIQ.
    3.1. Add the messages which you want to distribute.
    3.2 Generate Partner profiles.
    No coding is reqd. for this.
    BR,
    Suhas

  • How to Trigger an IDOC from SAP R/3 to two XI systems

    Hi experts,
       Can any one please tell me How to Trigger an IDOC from SAP R/3 to two XI systems at a time.
    My current production R/3 system sends a DELCERY01 IDOC to Production XI system ( Name : XIP) .
    I would like to route the same IDOC from production R/3 system to my Quality XI System ( Name XIQ) .
    Problem is production R/3 system triggers an IDOC once.
    Regards
    Ram.

    Hi Ravi,
      Thank you very much for your answer.
    As I am not completely aware of R/3 side,I am getting little problem in understanding your answer.
    Could you please explain the same in some what beter way.. Thank you ..

  • How to trigger IDOC'S from SAP

    Hi All,
    How to trigger IDOC's from SAP(ECC 6)..where can we check this in mii 11.5 weather it is fail/success
    Thanks,
    Abhi

    You can trigger LOIPRO, LOIPLO and a few others manually from POIT (SAP Txn).  Master Data related to orders can be triggered from POIM.  Depending on which IDocs you which to generate, there are other transactions to trigger different IDocs.
    You can also use Triggers from MII to generate IDocs in SAP using CLOI_DOWNLOAD_TRIGGER_MDAT (POIM equivalent) and CLOI_DOWNLOAD_TRIGGER_TRANS (POIT equivalent).
    There is also a rather nice post which detailed the process of using change pointers to automate the IDoc generation and download, but I am having trouble finding it.  Will continue to look and will post link when I find it.
    Regards,
    Mike
    I couldn't find the post I was looking for, but there is an informative note 390635 which may help.
    Edited by: Michael Appleby on May 5, 2009 1:29 PM

  • Call a unix script from ABAP program

    Can anybody help me on how to call a unix script from an ABAP program
    Regards
    Anjali

    Hi try the below code
    parameters : p_sfile(60) lower case
              "File to be moved
              "Eg : /home/in/SFILE1.txt
                p_dfile(60) lower case.
              "File's Destination
              "Eg: /home/archive/SFILE1.txt
    data : t_btcxpm
           like btcxpm occurs 0,
           p_addparam
           like sxpgcolist-parameters.
      concatenate
      '/home/ABAP/scripts/Archive_file.sh'
      p_sfile
      p_dfile
      into p_addparam separated by space.
      refresh t_btcxpm. clear t_btcxpm.
      call function 'SXPG_CALL_SYSTEM'
        exporting
          commandname = 'ZSHELL'
          additional_parameters = p_addparam
        tables
          exec_protocol = t_btcxpm
        exceptions
          no_permission              = 1
          command_not_found          = 2
          parameters_too_long        = 3
          security_risk              = 4
          wrong_check_call_interface = 5
          program_start_error        = 6
          program_termination_error  = 7
          x_error                    = 8
          parameter_expected         = 9
          too_many_parameters        = 10
          illegal_command            = 11
          others                     = 12.
      if sy-subrc = 0.
        write : /
        'File',p_sfile,'moved to',p_dfile.
      else.
        write : / 'Error Occured'.
      endif.

  • More on unix script from pl/sql

    Hi All,
    There was this discussion on starting unix scripts from within a pl/sql stored procedure started on August 31.
    All comments were targeted towards an oracle 8X solution.
    Does anyone have a solution for 7.3.4?
    Somebody mentioned something about using dbms_pipe package.
    So, just to rephrase the problem:
    - Need to execute any unix command/script from within a pl/sql block (stored procedure). Instance is oracle 7.3.4
    Thanks!
    Enrique

    Hi Juan,
    You can try this solution:
    enable in the the init file the parameter
    utl_file_dir="target_directory"In this way You permit the the DB to writing directly to the filesistem in the directory You specified.
    After restarting the istance You may write Your own code that, using the supplied package UTL_FILE, writes a file in that directory (es. my_script.sh)
    Then, instruct the cron daemon to execute every 1 minute this command.
    You may append to the script the self-destruction after the execution.
    I hope that this will help You.
    Max

  • Running a Unix script from a Java class

    I am trying to use SCP (Secure copy) to copy an xml file from my J2EE application to a remote Unix server using a Unix script. How can I run the Unix script from my Java class? I could not find any resource for this on the internet. Can someone help me with this please.
    Thanks

    I am trying this below program ,but i am getting the error please help me
    import com.jcraft.jsch.*;
    import com.jcraft.jsch.Channel;
    import com.jcraft.jsch.JSch;
    //import com.jcraft.jsch.JSchException;
    import com.jcraft.jsch.Session;
    //import com.jcraft.jsch.UserInfo;
    import java.io.*;
    public class testrad {
    public static void main(String args[])
    String user="usertvr";
    String host="5.34.12.1";
    String cmd="ls -l";
    JSch jsch = new JSch();
    try{
    Session session=jsch.getSession(user,host,22);
    session.setPassword("$yhaj23");
    //UserInfo usrInfo=new MyUserInfo();
    //session.setUserInfo(usrInfo);
    session.connect();
    Channel channel=session.openChannel("exec");
    ((ChannelExec) channel).setCommand(cmd);
    channel.setXForwarding(true);
    channel.connect();
    //code
    channel.setInputStream(System.in);
    // channel.setOutputStream(System.out);
    //((ChannelExec) channel).setErrStream(System.err);
    InputStream in = channel.getInputStream();
    channel.connect();
    byte[] tmp = new byte[1024];
    while (true)
    while (in.available() > 0)
    int i = in.read(tmp, 0, 1024);
    if (i < 0)
    break;
    System.out.print(new String(tmp, 0, i));
    if (channel.isClosed())
    in.close();
    // System.out.println("JSCH: exit-status: " +
    //channel.getExitStatus());
    break;
    try
    Thread.sleep(1000);
    catch (Exception ee)
    channel.disconnect();
    session.disconnect();
    }catch(Exception e)
    {e.printStackTrace();
    System.out.println("Exception"+e);}
    /*public static class MyUserInfo implements UserInfo {
    public String getPassword()
    { return "password"; }
    public String getPassphrase()
    { return ""; }
    public boolean promptPassword(String arg0)
    { return true; }
    public boolean promptPassphrase(String arg0)
    { return true; }
    public boolean promptYesNo(String arg0)
    { return true; }
    public void showMessage(String arg0)
    Here is the error
    com.jcraft.jsch.JSchException: UnknownHostKey: 5.128.0.10. RSA key fingerprint is 02:a0:d6:c0:6f:69:2c:a9:a7:fa:7c:71:1c:60:ed:57
         at com.jcraft.jsch.Session.checkHost(Unknown Source)
         at com.jcraft.jsch.Session.connect(Unknown Source)
         at com.jcraft.jsch.Session.connect(Unknown Source)
         at testrad.main(testrad.java:23)
    Exceptioncom.jcraft.jsch.JSchException: UnknownHostKey: 5.128.0.10. RSA key fingerprint is 02:a0:d6:c0:6f:69:2c:a9:a7:fa:7c:71:1c:60:ed:57
    Can some one help me please.
    I running this program from Windows to connect to remote unix boxes.

  • Call a unix script from pl/sql package

    Hi,
    Using 11.2.0.3 on AIX.
    Is it possible to call unix script from pl/sql package?
    I am cretaing a file in a directory but would like this to automatically be written to an archive directory as well.
    Could either use 2 utl_file.put_lines to 2 separate directories or 1 utl_file and cal script to archive file in another directory.?
    Thoughts?
    Thanks

    user5716448 wrote:
    What am I doing wrong?think how file name will look like:
    SQL> select 'file_name' || to_char(sysdate,'DD/MM/YYYY HH24:MI:SS') from dual;
    'FILE_NAME'||TO_CHAR(SYSDATE
    file_name15/08/2012 11:47:51Will AIX swallow such name? Obviously not. And, unfortunately, UTL_FILE.FCOPY doesn't raise an error in such case. So use someting like:
    UTL_FILE.FCOPY ('SOURCE_DIR',v_FILE_NAME,'DEST_DIR',v_file_name||to_char(sysdate,'DD_MM_YYYY_HH24_MI_SS'));SY.

  • Problem executing Unix script from Java...

    Hi there, I'm having trouble executing a unix script from a java program. The script receives multiple parameters and it seems that one of them ( or more ) is not well interpreted. When I run the script directly from a shell, the script executes without any errors. But, when I run the exact same script with the exact same parameters, it does not work.
    Here is the command to execute the script with all the parameters that is executed from the shell ( with success ) and also from the java program ( with errors ):
    /z/opus/dcap/intfu001.csh 'NODEBUG^NOTKPROF^NOSTACK' opus dcap JACQUES JACQUES '2625781' 'ORA$PIPE$001D00D70001' JOB^DEBUG^SINISIMU^STATPROD^DECTIDANC^81^503^4080^86^87^151^97^98^99 BUT^N^N^SPRI^0^13^24^3^J^05^N^19^19^19 >> /tmp/switcher8.999.null.pgm.test
    And here is my portion of code that executes the script:
    Runtime wShell = Runtime.getRuntime();
    Process wProc = wShell.exec(cmd_unix_final);
    wProc.waitFor();
    return wProc.exitValue();
    Please give me your thoughts on this!
    Thanks in advance!

    Ok.
    Let's proceed surgically, else we'll never solve or overcome anything.
    In the last your reply you wrote:
    the normal output is what I get when the script runs successfully, the script first prints a few things
    and then does stuff that takes at least 2 or 3 secondsWhat do you mean?
    -Finally have you got your script correctly executed?
    The stuffs you spoke of are really performed?
    If this is the case I can't see the prob.
    Is your concern only about exitValue() for it doesn't let you distinguish programmatically
    the success or failure of the script execution?
    Of course you surely already have a routine in your java code to handle
    exceptional situations of errors from the script.
    And the "normal output" is just what you must parse to detect those errors.
    Then who cares about exitValue() in this case?
    Don't invoke it, relay on the stdout and stderr of the script.
    -Or you get only a deceiving standard output
    that let you think the script execution went alright, while instead it didn't.
    In this case we have to investigate some other thing.
    I can't still exclude that the problem isn't related with the buffer size of the stdout
    allocated by the environment to the subprocess. You spoke of few things printed out.
    Be explicit. What's the size of the output you get?
    And is the "normal output" complete till the very last char
    or is it truncated from somewhere on?
    Also it's important that you hit a ps command after the java main process terminates
    (or simply when waitFor() returns) and see if the script subprocess hung up.
    As an alternative approach directly call your pro*C code from Java through JNI, instead of translating it.
    1. Exec.java
    public class Exec{
         static{
              System.loadLibrary("Exec");
         public static native void proCFunct();
         public static void main( String[] args){
              proCFunct();
    }2. javac Exec.java
    3. javah Exec
    4.Exec.c
    #include "Exec.h"
    JNIEXPORT void JNICALL Java_Exec_proCFunct(JNIEnv * a, jclass b){
         //here call the function that executes the script
    5. cc -G -I$JAVA_HOME/include -I$JAVA_HOME/include/solaris -I$YOUR_INCLUDES Exec.c -o libExec.so
    6. setenv LD_LIBRARY_PATH .
    7. java Exec

  • Run a UNIX Script from java

    Hi,
    how can i run a unix script from java application. This java application is on windows.
    How can i do this.
    thanks,

    Hi,
    how can i run a unix script from java application.
    This java application is on windows.
    So I think it's safe to assume that the target script is on a remote unix server.
    Take a look at http://sourceforge.net/projects/sshtools/

  • Calling UNix Script from portal Form

    Has anyone conquered this issue through jav or plsql. I need to call a unix script from the portal form when I select the insert button.

    I have several very convoluted ways which all work, but I have always thought there should be more straightfwd ways. Fundamentally the easiest way to call something from the Insert button is to add some PL/SQL code before (or after) the "doInsert();" call in the Insert Button event handler.
    What seems to be lacking is the ability to get from pl/sql to the o/s. So until we know how to do that you have to call a method in Java to execute o/s commands - specifically you can use Runtime.getRuntime().exec(cmd); where Runtime is a class in java.lang, and cmd is the actual o/s command (script or whatever).
    How to call this Java is then where you have several options:
    1. Compile this piece of Java into the Oracle DB as a SP.
    2. Deploy this piece of Java within a Java servlet on a 9iAS instance. Then have another SP call this servlet using the utl_http package (begin_request and other sp's within package).
    Which options would depend on several factors including your preference but most importantly whether you have a DB or a 9iAS instance on the machine where you want to execute the script. If you have neither you have a problem. In such cases I have used a standalone OC4J container which has a very small footprint.
    As I said these methods are all quite convoluted and if anyone else has anything better I would like to know (but they work quite reliably).
    Cheers.
    Anton.

  • Accessing unix script from Apex

    Hi There,
    Is it possible to access unix script from apex?
    Or to run a batch file through apex?
    Please help!!
    Thanks in advance,
    Pushpesh Pallav

    The solution depends on the purpose of the script.
    "I want to run a database backup"
    learn RMAN, create an RMAN repository, and have Oracle backup itself
    "I want to backup a schema on demand"
    use dbms_datapump
    "I want to put/get a blob to/from a file on an internal machine"
    one method:
    Install and register Oracle Agent on internal machine
    use dbms_scheduler.put_file()/get_file()
    "I want to get a file on an external machine that is available via HTTP(s)"
    I've used ORDDoc( 'http://...' ) to get this file.
    "I want to run the script and parse the results. - no input parameters are needed"
    Enhance the script to return CSV like results
    Then, create an EXTERNAL TABLE with a preprocessor
    ".. and the script returns performance matrix of a server"
    I believe Oracle has already written (and incorporated) those scripts.
    "..and the script checks to see if a new file exists"
    DBMS_SCHEDULER.FILE_WATCHER()
    "I want to give it some parameters,run the script, and then parse the results"
    Wrap the script with SOAP/REST.
    Example wrapper stuff:
    http://soaplab.sourceforge.net/soaplab2/
    MK

  • Call Unix Script from JSP.

    Hi,
    I need to run a unix script from a JSP page.
    JSP pages reside on a different machine.
    How can i call the unix script resides on different machine from JSP.
    Thanks,
    Narendra

    yah. I can access that machine telnet and having all credentials of that system.
    Can you please share the code needed for this.
    Thanks,
    Narendra

  • Excute unix script from java.

    Hi need to excute unix script from java application.
    My code is:
    public class Test
    public static void main(String args[])
         try{
         p = Runtime.getRuntime().exec("./qfe0"); //qfe0 is the name of the script.
    p.waitFor();
    catch(Exception e)
    e.printStackTrace();
    My problem is that using the waitFor() statement stuck the the script. if i don't use the waitFor() it works good but then i don't know when the script is finished.
    Any idea?

    The problem is likely to be that you script is either waiting for input or has filled the stdout buffer and you are not emptying it. Search this forum for this as its been answered many times before.

Maybe you are looking for

  • Exporting Tcode MKVZ to Excel File

    Hi Experts, I'm trying to export the output of tcode MKVZ (List of Vendors: Purchasing) to a local file in the format of spreadsheet. I successfully exported the file but when I reviewed the content on the excel file, some rows were missing and other

  • Iphone wifi connection problem

    I just bought an Iphone and when it attempts a wifi connection It asks for a password to my network which I have totally forgotten. When I tried to access the setup site (192.168.1.1) a dialog box popped up with the following message "A username and

  • Flex,rtmp & adding one frame on display - protection from stolen content - please help.

    Hello First of all I must say that I only owner not creator but I need help to give some hints for person who do all webdesing stuff for me becouse he is out of ideas now. Problem: I have website with movies displayed in flex and rtmp. Movies are not

  • Screen Coating on Macbook Pro Late 2013

    So I cleaned my Macbook Pro screen earlier using their provided cloth and the tiniest bit of water. After cleaning and looking, some of what seems like the coating has either worn off or deteriorated on the bottom of the screen. Can anyone confirm if

  • SUM analytical function

    Hi, I am using the SUM analytical function to accumulate some data from one record to the other record (data per month): TPS_MOI_CODE     PRD_PRD_CODE     PDV_PDV_CODE     RTTCAVCANV 200510     01     9302     -8050 200511     01     9302     -15500