문제

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