Created
April 1, 2015 16:21
-
-
Save hatifnatt/6d9fd930d2e409362ef5 to your computer and use it in GitHub Desktop.
Script to create dummy files with dates in past. Created to test GFS backup rotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to create dummy files with dates in past | |
# Count of months and weeks must not be greater than 99, count of days must not be greater than 999 | |
### CONFIG BEGIN ### | |
# Count of files to create, including current month, week and day | |
MONTHS=12 | |
WEEKS=10 | |
DAYS=14 | |
# Day of week (1..7); 1 is Monday for weekly files | |
WEEKDAY=7 | |
# Put date into file. 1 - Yes, 0 - No | |
PUTDATE=0 | |
# Time for newly created files | |
HH="03" | |
MM="00" | |
### CONFIG END ### | |
if [ ! -d "./dummy/monthly" ] || [ ! -d "./dummy/weekly" ] || [ ! -d "./dummy/daily" ]; then | |
mkdir -p ./dummy/{monthly,weekly,daily} | |
fi | |
# This month | |
THISMONTH=$(date +"%Y%m")01 | |
# This week | |
case ${WEEKDAY} in | |
1) THISWEEK=$(date -d "last Monday" +"%Y%m%d");; | |
2) THISWEEK=$(date -d "last Tuesday" +"%Y%m%d");; | |
3) THISWEEK=$(date -d "last Wednesday" +"%Y%m%d");; | |
4) THISWEEK=$(date -d "last Thursday" +"%Y%m%d");; | |
5) THISWEEK=$(date -d "last Friday" +"%Y%m%d");; | |
6) THISWEEK=$(date -d "last Saturday" +"%Y%m%d");; | |
7) THISWEEK=$(date -d "last Sunday" +"%Y%m%d");; | |
*) echo "Wrong WEEKDAY"; exit 1;; | |
esac | |
# This day | |
TODAY=$(date +"%Y%m%d") | |
# Counter | |
CNT=0 | |
# Month cycle | |
while [ ${CNT} -lt ${MONTHS} ]; do | |
# echo $(date -d "${THISMONTH} - ${CNT} month" +"%Y%m%d")T${HH}:${MM} | |
touch -d $(date -d "${THISMONTH} - ${CNT} months" +"%Y-%m-%d")T${HH}:${MM} ./dummy/monthly/$(printf "%.2d" ${CNT})-months | |
[ ${PUTDATE} -eq 1 ] && echo $(date -d "${THISMONTH} - ${CNT} month" +"%Y%m%d")T${HH}:${MM} > ./dummy/monthly/$(printf "%.2d" ${CNT})-months | |
CNT=$((${CNT}+1)) | |
done | |
# Reset counter | |
CNT=0 | |
# Week cycle | |
while [ ${CNT} -lt ${WEEKS} ]; do | |
# echo $(date -d "${THISWEEK} - ${CNT} weeks" +"%Y%m%d")T${HH}:${MM} | |
touch -d $(date -d "${THISWEEK} - ${CNT} weeks" +"%Y-%m-%d")T${HH}:${MM} ./dummy/weekly/$(printf "%.2d" ${CNT})-weeks | |
[ ${PUTDATE} -eq 1 ] && echo $(date -d "${THISWEEK} - ${CNT} weeks" +"%Y%m%d")T${HH}:${MM} > ./dummy/weekly/$(printf "%.2d" ${CNT})-weeks | |
CNT=$((${CNT}+1)) | |
done | |
# Reset counter | |
CNT=0 | |
# Day cycle | |
while [ ${CNT} -lt ${DAYS} ]; do | |
# echo $(date -d "${TODAY} - ${CNT} days" +"%Y%m%d")T${HH}:${MM} | |
touch -d $(date -d "${TODAY} - ${CNT} days" +"%Y-%m-%d")T${HH}:${MM} ./dummy/daily/$(printf "%.3d" ${CNT})-days | |
[ ${PUTDATE} -eq 1 ] && echo $(date -d "${TODAY} - ${CNT} days" +"%Y%m%d")T${HH}:${MM} > ./dummy/daily/$(printf "%.3d" ${CNT})-days | |
CNT=$((${CNT}+1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment