Page 1 of 1

Running External Command using * Operator

PostPosted: Mon Jun 29, 2009 1:25 am
by xaverianite
Hello All,

I want to schedule clean up of file-system logs files from the following directory via external command:

/usr/sap/<SID>/D00/work

Files to be cleaned : CPICTRC* or *.log

When I schedule the command via SM69/SM49, as following

Command = rm
Parameter = /usr/sap/PR1/D00/work/CPICTRC* or /usr/sap/PR1/D00/work/*.log

It gives an error saying directory could not be found.

But if I give the complete file name like /usr/sap/PR1/D00/work/CPICTRC1146996, then it works fine.

The problem is it does to interpret * just like the AIX system would interpret.

Could you please let me know how can I achieve the normal * functionality via SAP External Command execution just the AIX system would interpret.


Thanks,
Saurabh.

Re: Running External Command using * Operator

PostPosted: Mon Jun 29, 2009 2:56 am
by Zavaros
Hello,

"*" operator is replaced by the shell interpreter. So in your case the rm command really tries to delete the file "*.log" ... which does not exists.

As a workaround you can write a script or use the following command:
Code: Select all
find /usr/sap/PR1/D00/work/ -name "*.log" -mtime +30 -exec rm {} ;\


Regards,

Zav

PS: "-mtime +30" is to delete only files that are more than 30 days old

Re: Running External Command using * Operator

PostPosted: Mon Jun 29, 2009 8:51 am
by Snowy
try calling a shell script instead. this script is to be installed at Os level.

Re: Running External Command using * Operator

PostPosted: Mon Jun 29, 2009 9:12 am
by xaverianite
Thank you Zavaros and Snowy, I am going to create the Script and try out the suggestions.
I am sure it will work.

Thank you both of you once again for the workaround.


Thanks,
Saurabh.

Re: Running External Command using * Operator

PostPosted: Fri May 29, 2015 7:58 am
by kid
Dear all,

you can use this piece of code:

Code: Select all
  CALL FUNCTION 'RZL_READ_DIR_LOCAL'
    EXPORTING
      name               = fname
    TABLES
      file_tbl           = file_tbl
    EXCEPTIONS
      argument_error     = 1
      not_found          = 2
      no_admin_authority = 3
      OTHERS             = 4.


    LOOP AT file_tbl ASSIGNING <file>.

      IF <file>-name CP '*.gz' OR
       <file>-name CP '*.csv'.

        lv_delparam =  fname && <file>-name.

        CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
          EXPORTING
...


Best regards,
Alexander