I have a Debian server which runs a service using multiple config files (in a similar way to apache2) which I need to add an expiration date to. The config file that has an expiration date starts with a comment containing the it:


The problem is that not all files need to have an expiration date. These don't have this comment.

I need to write a bash script that'll be regularly run by cron, which would parse the first line in every config file, and if it's expired, it'd perform an action in this file (e.g. move to another folder) and then reload or restard the service in question. Files without the expiration date comment have to be ignored (no actions need to be performed on these).

How to reliably verify the expiration of the file?


Interesting question.

Below code is written loosely to address the issue.

Loosely, because following code assume the files having "space" in it. Also assuming that, first line of every .conf script will have timestamp as "#YYYYMMDD"

Feel free to modify it as required.


for i in `find /etc -name *.conf`
    Current_date=$(date +"%Y%m%d")
    date_to_compare=$(head -n1 $i | sed 's/^#//g')

    if [ $Current_date -ge $date_to_compare ];  then
          echo "Move the file to new directory"
          echo "Start the relevant service"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.