cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Experts,

Can some one give the syntax in unix .

Thanks

SKB

Former Member
0 Kudos

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

former_member198401
Active Contributor
0 Kudos

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