Вопрос

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