Last active
April 6, 2022 13:00
-
-
Save mhenes/8c4a4aa6e1d5a328f602 to your computer and use it in GitHub Desktop.
Bash date module
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 | |
# Name: Mark Henes | |
# Date: 10-18-2015 | |
# Purpose: Module of date formats and commands. | |
### | |
# Different formats, functions, and loops as timestamp counters to be used as a module for parent scripts. | |
# Day | |
function d { | |
date "+%d" | |
} | |
# Month | |
function m { | |
date "+%m" | |
} | |
# Year | |
function Y { | |
date "+%Y" | |
} | |
# Hour | |
function H { | |
date "+%H" | |
} | |
# Minute | |
function M { | |
date "+%M" | |
} | |
# Second | |
function S { | |
date "+%S" | |
} | |
# Month, Day. | |
function md { | |
date "+%m-%d" | |
} | |
# Month, Day, Year. | |
function mdY { | |
date "+%m-%d-%Y" | |
} | |
# Month, Day, Year, Hour. | |
function mdYH { | |
date "+%m-%d-%Y%n%H" | |
} | |
# Month, Day, Year, Hour, Minute. | |
function mdYHM { | |
date "+%m-%d-%Y%n%H:%M" | |
} | |
# Month, Day, Year, Hour, Minute, Second. | |
function mdYHMS { | |
date "+%m-%d-%Y%n%H:%M:%S" | |
} | |
# Text, Month, Day, Year, Hour, Minute, Second. | |
function mdYHMS-text { | |
date "+DATE: %m-%d-%Y%nTIME: %H:%M:%S" | |
} | |
# One second counter for 10 seconds. | |
function one_sec_counter_for_10 { | |
for i in `seq 1 10`; | |
do | |
sleep 1 | |
mdYHMS | |
done | |
} | |
# One second counter for 30 seconds. | |
function one_sec_counter_for_30 { | |
for i in `seq 1 30`; | |
do | |
sleep 1 | |
mdYHMS | |
done | |
} | |
# One second counter for 60 seconds. | |
function one_sec_counter_for_60 { | |
for i in `seq 1 60`; | |
do | |
sleep 1 | |
mdYHMS | |
done | |
} | |
### | |
# OUTPUT | |
### | |
# Uncomment hashtag to write to file. Change function to output different format. | |
mdYHMS # > date.txt | |
### | |
# Call this script from another script by the following usage example: | |
# bash date.sh | |
# /bin/bash /path/to/script | |
### | |
# End | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment