سؤال

So I have a bash script that I need to run weekly but I don't know how to format the date so I can automate the script.

My script:

#!/bin/bash


tod=$(date +%F_%H%M%S)
echo "start"
echo $tod

tar --newer-mtime=20130811 -cvzf /path/to/file/xz$tod-last6months.tar /path/to/what/I'm/tarring

echo "done"
exit

I want to replace the mtime=20130811 with something similar to the tod=$(date +%F_%H%M%S) so I don't have to manually change the date and so it will only tar what has changed over the last 6 months.

Thanks in advance.

هل كانت مفيدة؟

المحلول

--newer-mtime=$(date --date='6 months ago' +%Y%m%d)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top