<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>http://wiki.ciscolinux.co.uk/index.php?action=history&amp;feed=atom&amp;title=Linux_shell%2FFunctions</id>
	<title>Linux shell/Functions - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.ciscolinux.co.uk/index.php?action=history&amp;feed=atom&amp;title=Linux_shell%2FFunctions"/>
	<link rel="alternate" type="text/html" href="http://wiki.ciscolinux.co.uk/index.php?title=Linux_shell/Functions&amp;action=history"/>
	<updated>2026-04-05T07:49:44Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.2</generator>
	<entry>
		<id>http://wiki.ciscolinux.co.uk/index.php?title=Linux_shell/Functions&amp;diff=6899&amp;oldid=prev</id>
		<title>Pio2pio: Created page with &quot;A bunch of useful functions:  &lt;source lang=bash&gt; cat &gt; common_functions.sh &lt;&lt;EOF #!/usr/bin/env bash  ########################################################################################## # log: trace message to stdout # Globals: #   None # Arguments: #   - $1: msg to render, if empty log does nothing #   - $2: level tag, defaults to INFO # Returns: #   outputs to stdout ########################################################################################## funct...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.ciscolinux.co.uk/index.php?title=Linux_shell/Functions&amp;diff=6899&amp;oldid=prev"/>
		<updated>2022-08-24T21:59:11Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;A bunch of useful functions:  &amp;lt;source lang=bash&amp;gt; cat &amp;gt; common_functions.sh &amp;lt;&amp;lt;EOF #!/usr/bin/env bash  ########################################################################################## # log: trace message to stdout # Globals: #   None # Arguments: #   - $1: msg to render, if empty log does nothing #   - $2: level tag, defaults to INFO # Returns: #   outputs to stdout ########################################################################################## funct...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;A bunch of useful functions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
cat &amp;gt; common_functions.sh &amp;lt;&amp;lt;EOF&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
&lt;br /&gt;
##########################################################################################&lt;br /&gt;
# log: trace message to stdout&lt;br /&gt;
# Globals:&lt;br /&gt;
#   None&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   - $1: msg to render, if empty log does nothing&lt;br /&gt;
#   - $2: level tag, defaults to INFO&lt;br /&gt;
# Returns:&lt;br /&gt;
#   outputs to stdout&lt;br /&gt;
##########################################################################################&lt;br /&gt;
function log() {&lt;br /&gt;
    msg=$1&lt;br /&gt;
    if [[ -n ${msg} ]];then&lt;br /&gt;
        level=${2:-&amp;quot;INFO&amp;quot;}&lt;br /&gt;
        echo &amp;quot;$(date +&amp;quot;%Y-%m-%dT%T.%3N&amp;quot;) - $level - $msg&amp;quot; &amp;amp;&amp;gt;/dev/stderr&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
##########################################################################################&lt;br /&gt;
# current_datetime: returns string with date time formated as ddMMyyyy-HmS&lt;br /&gt;
# Globals:&lt;br /&gt;
#   None&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   None&lt;br /&gt;
# Returns:&lt;br /&gt;
#   None&lt;br /&gt;
##########################################################################################&lt;br /&gt;
function current_datetime() {&lt;br /&gt;
    echo $(date +&amp;quot;%Y%m%d-%H%M%S&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
##########################################################################################&lt;br /&gt;
# die: function exit with error message&lt;br /&gt;
#&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   $1 - exit code&lt;br /&gt;
#   $2.... - message&lt;br /&gt;
# Returns:&lt;br /&gt;
#   exit and exit code selected&lt;br /&gt;
##########################################################################################&lt;br /&gt;
function die() {&lt;br /&gt;
    retcode=$1; shift&lt;br /&gt;
    echo $@&lt;br /&gt;
    exit $retcode&lt;br /&gt;
}&lt;br /&gt;
##########################################################################################&lt;br /&gt;
# checkEnvOrDie: check for the existence of a variable and if not found exits session&lt;br /&gt;
#&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   $1 - name of the variable, i.e. checkEnvOrDie HOME&lt;br /&gt;
# Returns:&lt;br /&gt;
#   nothing, or exit with code 400 if fails&lt;br /&gt;
##########################################################################################&lt;br /&gt;
function checkEnvOrDie() {&lt;br /&gt;
    env | grep $1 &amp;gt; /dev/null&lt;br /&gt;
    if [[ $? -ne 0 ]]; then&lt;br /&gt;
        die 400 &amp;quot;Env variable $1 must be set!&amp;quot;;&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pio2pio</name></author>
	</entry>
</feed>