Timestamp (Bash)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

Zie ook Timestamp (MySQL).

Some examples:

echo $(date +'%Y%m%d-%H%M%S')   # 20220608-161601
echo $(date +'%Y.%m.%d-%H.%M.%S')   # 2022.06.08-16.14.52
last_month=$(($(date +'%m')-1))
[ $month = 0 ] && month=12

Voorbeeld uit een backup-routine:

#!/bin/bash

#########################################
# Variabelen
#########################################
#
db="dwh"
timestamp=$(date +'%Y%m%d-%H%M%S')
doel=$timestamp"-dwh.sql"

#########################################
# Dumpen
#########################################
#
mysqldump --routines $db > $doel
gzip $doel

Zie ook