11#! /bin/bash
22
33# Get DateTime
4- function lhs_date_get_with_format() {
4+
5+ function lhs_cmd_date_get_month() {
6+ date +%m
7+ }
8+
9+ function lhs_cmd_date_get_year() {
10+ date +%Y
11+ }
12+ function lhs_cmd_date_get_with_format() {
513 echo $( date " +" ${1:- " %Y-%m-%d-%H-%M-%S" } )
614}
715
8- function lhs_date_get_with_format_yyyymmdd() {
9- lhs_date_get_with_format " %Y%m%d"
16+ function lhs_cmd_date_get_with_format_yyyymmdd() {
17+ lhs_cmd_date_get_with_format " %Y%m%d"
18+ }
19+
20+ function lhs_cmd_date_get_with_format_cw_log() {
21+ lhs_cmd_date_get_with_format " %Y-%m-%d %H:%M:%S"
22+ }
23+
24+ function lhs_cmd_date_get_epoch_time() {
25+ # unix-time-in-milliseconds
26+ date -d ' 0 hour ago' +%s%N | cut -b1-13
27+ }
28+
29+ # TODO function lhs_cmd_time_convert_echo_to_human_readable_formaton_name to convert epoch time to human readable formnat.
30+ # @param $1: the value of epoch time and $2: the formant(default is %Y-%m-%d-%H-%M-%S)
31+ # @return
32+ #
33+ function lhs_cmd_time_convert_echo_to_human_readable_format() {
34+
35+ # TODO Later (it didn't work rightnow)
36+ local default_date_format=+${2:- ' %Y-%m-%d-%H-%M-%S' }
37+ date -r ${1:? ' epoch_value is unset or empty' } ${default_date_format}
1038}
1139
1240# Password generate
13- function lhs_password_generate () {
41+ function lhs_cmd_password_generate () {
1442 # openssl rand -base64 10 | tr -d '='
1543
1644 cd /tmp > /dev/null
@@ -19,7 +47,7 @@ function lhs_password_generate() {
1947}
2048
2149# Get DateTime
22- function lhs_file_name_get_random_name () {
50+ function lhs_cmd_file_name_get_random_name () {
2351 local file_name=${1:- ' FILENAME' }
2452 cd /tmp > /dev/null
2553 mktemp ${file_name} -XXXXXXXXXXXXXX
@@ -44,7 +72,7 @@ function lhs_file_name_get_random_name() {
4472# set +x
4573# }
4674
47- function lhs_run_commandline_with_retry () {
75+ function local_local_lhs_run_commandline_with_retry () {
4876 local lhs_commandline=$1
4977 local silent_mode=$2
5078 local retry_counter=0
@@ -75,25 +103,30 @@ function lhs_run_commandline_with_retry() {
75103
76104}
77105
78- function lhs_run_commandline () {
79- lhs_run_commandline =$1
80- lhs_run_commandline =" ${lhs_run_commandline :? ' lhs_run_commandline is unset or empty' } "
81- lhs_run_commandline_with_logging " ${lhs_run_commandline } "
106+ function local_lhs_run_commandline () {
107+ local_lhs_run_commandline =$1
108+ local_lhs_run_commandline =" ${local_lhs_run_commandline :? ' local_lhs_run_commandline is unset or empty' } "
109+ local_local_lhs_run_commandline_with_logging " ${local_lhs_run_commandline } "
82110}
83111
84- function lhs_commandline_logging() {
112+ function local_lhs_commandline_logging() {
113+
114+ local log_file_path=${aws_cli_logs} /${ASSUME_ROLE} .log
115+ local tee_command=" tee -a ${lhs_cli_log_file_path} "
116+
85117 local eval_commandline=${2:- ' False' }
86- lhs_commandline_logging=$( echo ${1:? ' lhs_commandline is unset or empty' } | tr -d ' \t' | tr -d ' \n' )
118+
119+ local local_lhs_commandline_logging=$( echo ${1:? ' lhs_commandline is unset or empty' } | tr -d ' \t' | tr -d ' \n' )
87120
88121 if [[ " ${eval_commandline} " == " True" ]]; then
89- echo " ${lhs_commandline_logging } "
122+ echo " ${local_lhs_commandline_logging } "
90123 else
91- echo " Running commandline [ ${lhs_commandline_logging } ]"
124+ echo " Running commandline [ ${local_lhs_commandline_logging } ]" | eval $tee_command
92125 fi
93126
94127}
95128
96- function lhs_run_commandline_with_logging () {
129+ function local_local_lhs_run_commandline_with_logging () {
97130 lhs_commandline=$1
98131 if [ " $lhs_show_log_uploaded " = " true" ]; then
99132 local tee_command=" tee -a ${lhs_cli_log_file_path} ${lhs_cli_log_uploaded_file_path} "
@@ -108,18 +141,18 @@ function lhs_run_commandline_with_logging() {
108141 fi
109142
110143 echo " ------------------------------STARTED--$( date ' +%Y-%m-%d-%H-%M-%S' ) -----------------------------------------" | eval $tee_command > /dev/null
111- lhs_commandline_logging $1 | eval $detail_commandline_tee_command
112- lhs_commandline_result=$( lhs_run_commandline_with_retry " ${lhs_commandline} " " ${ignored_error_when_retry} " )
144+ local_lhs_commandline_logging $1 | eval $detail_commandline_tee_command
145+ lhs_commandline_result=$( local_local_lhs_run_commandline_with_retry " ${lhs_commandline} " " ${ignored_error_when_retry} " )
113146 echo $lhs_commandline_result | eval $tee_command
114147 echo " ------------------------------FINISHED-$( date ' +%Y-%m-%d-%H-%M-%S' ) -----------------------------------------" | eval $tee_command > /dev/null
115148}
116149
117- function lhs_util_rm_space () {
150+ function local_lhs_util_rm_space () {
118151 # echo "${1}" | sed 's/[[:space:]]//g'
119152 # https://stackoverflow.com/questions/13659318/how-to-remove-space-from-string
120153 echo " ${1// +([[:space:]])/ } "
121154}
122155
123- function lhs_util_format_commandline_one_line () {
156+ function local_lhs_util_format_commandline_one_line () {
124157 echo ${1} | tr -d ' \t' | tr -d ' \n' | tr -s ' '
125158}
0 commit comments