This website is not affiliated with, sponsored by, or approved by SAP AG.

Running External Command using * Operator

Basis (Basis Technology Modules: Basis Component/System Administration, GUIs)

Moderators: Snowy, thx4allthefish

Running External Command using * Operator

Postby xaverianite » Mon Jun 29, 2009 1:25 am

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.
xaverianite
 
Posts: 114
Joined: Sun Jun 08, 2003 5:07 am

Re: Running External Command using * Operator

Postby Zavaros » Mon Jun 29, 2009 2:56 am

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
Zavaros
 
Posts: 756
Joined: Thu Oct 24, 2002 10:50 pm
Location: Hungary

Re: Running External Command using * Operator

Postby Snowy » Mon Jun 29, 2009 8:51 am

try calling a shell script instead. this script is to be installed at Os level.
SapFans Moderator

Search: http://www.sapfans.com/forums/search.php
Notes: http://service.sap.com/notes
Help: http://help.sap.com
Rules: http://www.sapfans.com/forums/viewtopic.php?t=344127
Snowy
 
Posts: 28767
Joined: Mon Oct 21, 2002 2:33 pm
Location: 3.1415926535

Re: Running External Command using * Operator

Postby xaverianite » Mon Jun 29, 2009 9:12 am

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.
xaverianite
 
Posts: 114
Joined: Sun Jun 08, 2003 5:07 am

Re: Running External Command using * Operator

Postby kid » Fri May 29, 2015 7:58 am

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
kid
 
Posts: 9
Joined: Wed Jul 26, 2006 10:11 am


Return to Basis

Who is online

Users browsing this forum: Google [Bot] and 7 guests





loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.