简体   繁体   中英

How to append current date to property file value every day in Unix?

I've got a property file which is read several times per day by an external application in order to process some files. One of the properties tells the app where to store the processed files. Application runs on Linux.

success_path=/u02/oapp/success

The problem is that every day several files are thrown in that path and after several months, I would have thousands of files in this plane folder.

Question: How can I append the current date to this property file so it would look like:

success_path=/u02/oapp/success/dd-MMM-yyyy

This would be updated every day at 12:00AM so for example today it would be

success_path=/u02/oapp/success/28-JAN-2017

The file is /u02/oapp/configuration/oapp.properties

Thanks in advance

Instead of appending current date to the property, add additional logic to the code that stores the processed files so that:

  • it takes the base directory from the property file ( success_path in your case)
  • it creates a year/month/day directory to store the files

Something like:

/u02/oapp/success/year/month/day (as in `/u02/oapp/success/2017/01/01`)
or
/u02/oapp/success/yearmonth/day  (as in `/u02/oapp/success/201701/01`)
or
/u02/oapp/success/yearmonthday   (as in `/u02/oapp/success/20170101`)

If you don't have the capability to change the app's behavior, you might need to write a cron job that periodically moves the files external to the app.

jq -Rr 'select(startswith("success_path="))="success_path=/u02/oapp/success/"+(now|strflocaltime("%d-%b-%Y")|ascii_upcase)' /u02/oapp/configuration/oapp.properties | sponge /u02/oapp/configuration/oapp.properties

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM