Skip to Content
0

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

Aug 02, 2017 at 01:20 PM

90

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Arun Sasi Aug 02, 2017 at 02:08 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Aug 02, 2017 at 02:18 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Aug 02, 2017 at 02:26 PM
0

Hi Experts,

Can some one give the syntax in unix .

Thanks

SKB

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Apr 12 at 06:35 AM
0

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));

Share
10 |10000 characters needed characters left characters exceeded