Created
October 26, 2023 19:34
-
-
Save roychri/77301c17fd5d64cbaf452996e727d179 to your computer and use it in GitHub Desktop.
How to loop with unix timestamp modifier in busybox date (alpine)
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/sh | |
# Go back 1 hour for 1000 loops to add data to redis. | |
# Inspired by: | |
# * https://unix.stackexchange.com/questions/339938/busybox-date-command-set-time-with-unix-timestamp | |
# * https://unix.stackexchange.com/questions/22600/how-to-get-3-minutes-future-date | |
# * https://unix.stackexchange.com/questions/494581/date-command-in-busybox-not-accepting-formatted-input-date | |
for H in $(seq 1 1000); do | |
# Go back in time by one more hour | |
TS=$(date -d "@$(( `date +%s` - (3600 * ${H} * 30) ))" +%s); | |
# Add some data to redis based on this timestamp. | |
redis-cli zadd checkins-${TS}-${TS} ${TS}000 ${TS}000; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment