Skip to Content
avatar image
Former Member

BODS unix script not working to delete the older files other than x days

Hello Guys,

I want to remove the xml files based on the retention period from "path/folder" in the sap bods using unix script.

ex:if i give $GV_RETENTION_PERIOD = 4 means,it should delete the xml files from the path sharepath/folder other than 4 days.

print( exec('ksh', '-c "find sharepath/folder -type f -name \'*.xml\' -mtime +[$GV_RETENTION_PERIOD] -exec rm {} " ' , 8));

But the script is not working,its throwing the error like this:

error---> 1: find: invalid argument `1' to `-mtime'.

i tried another way also,but not working

print( exec('ksh', '-c "findsharepath/folder -type f -name \'*.xml\' -mtime + [$GV_RETENTION_PERIOD] -delete" ',8));

but throwing the same error:

error---> 1: find: invalid argument `1' to `-mtime'.

Please help on this,wehre iam doing wrong.

Thanks

SKB

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Aug 02, 2017 at 02:08 PM

    It works when using the CMD in windows but not sure about passing the global variable in unix shell command.

    2211245 - How to pass a Global Vairable in Exec() - Data Services

    Can you check with SAP Support Team.

    Regards

    Arun Sasi

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 02, 2017 at 02:18 PM

    Hi Arun,

    Thanks for prompt reply.

    Can you please provide the syntax by using the CMS in windows.

    i will try to execute it.

    Thanks

    SKB

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 02, 2017 at 02:26 PM

    Hi Experts,

    Can some one give the syntax in unix .

    Thanks

    SKB

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 12 at 06:35 AM

    For deleting files in the Archive folder you can use below code.

    Replace the GV with your path and change the values +30, below code is used to removing the files which is older than 30days.

    For Linux environment :

    print( exec('ksh', '-c "find [$G_FILE_DELETE] -mtime +30 -delete " ' , 8));

    For Windows:

    print(exec( 'powershell','"Get-ChildItem –Path

    [$G_FILE_DELETE] –Recurse | Where-Object\{$_.LastWriteTime –lt (Get-Date).AddDays(-30)\} | Remove-Item"',8));

    Add comment
    10|10000 characters needed characters exceeded