Skip to content

Commit

Permalink
Adding example inline scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
FBnil committed Mar 17, 2024
1 parent 7e8f271 commit 202be51
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
40 changes: 40 additions & 0 deletions extra/example_scripts/os.show.boottime=+
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
ARG=$1

_TZ=UTC
if [ -z "$ARG" ];then
ARG=$_TZ
else
_TZ=$ARG
# A selection of deprecated zone aliases, we translate these to current TZ syntax
ZoneAlias=("CET" "Europe/Paris" "IST" "Asia/Kolkata" "EST" "America/Cancun" "EST5EDT" "America/New_York" "PRC" "Asia/Shanghai" "ROC" "Asia/Taipei" "ROK" "Asia/Seoul")
size=${#ZoneAlias[@]}
for ((i=0; i < size; i++,i++)); do
[ "$ARG" == "${ZoneAlias[$i]}" ] && _TZ="${ZoneAlias[$i+1]}"
done
fi

# This is a normal comment. This will not be displayed in the help.
# When transmitting scripts through ssh-batch, all comments are skipped, so you do not waste bandwidth.

# Print out the Linux reported timezone
CTZ=$(TZ=${_TZ} date +%Z)
# Here we try a who -b, but if you have an older Linux, the -b option does not exist. In that case
# Try uptime -s
echo $((TZ=${_TZ} who -b||TZ=${_TZ} uptime -s) | sed -e 's/^[[:space:]]*//') $CTZ
# Help can be added in any position of the script. In this case, I put it almost at the end.
#: Show the Linux boot time in the selected timezone.
#: The default TimeZone is <B>UTC, which you can change with a <B>parameter.
#+: you can select from the following deprecated timezones:
#+: <B>CET <B>IST <B>EST <B>EST5EDT <B>PRC <B>ROC <B>ROK
#+: Note: During CEST, CET will mean CEST.
#+: <Y>Example: <L>./evidencer <L>os.show.boottime=# <L>-- <L>CET
#+: <Y>Example: <L>./evidencer <L>os.show.boottime=# <L>-- <L>Europe/Lisbon
#+: <C>See: <A>https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
#+: So instead of <B>WET you need to use <B>Europe/Lisbon (although WET still works)
# Throw in a bit of reboot history, for good measure:
TZ=$_TZ last reboot |head -4
4 changes: 4 additions & 0 deletions extra/example_scripts/os.show.cpu=+
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

lscpu | grep -e "^CPU(s):" | cut -f2 -d: | awk '{print $1}'
#: Display the number of CPU's a (virtual)machine has.
24 changes: 24 additions & 0 deletions extra/example_scripts/os.show.free=+
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
ARG=$1

if [ -z "$ARG" ];then
free -h
else
free $@
fi

#: Show the Linux Memory Usage.
#: The default is <B>-h, Human readable format, which you can change with a parameter.
#=: See the manual for <B>free for all the options. Some options are:
#+: <B>-b<:>, <B>--bytes Display the amount of memory in bytes.
#+: <B>-k<:>, <B>--kibi Display the amount of memory in kibibytes. (official default)
#+: <B>-g<:>, <B>--gibi Display the amount of memory in gibibytes.
#+: <B>--giga Display the amount of memory in gigabytes.
#=: These two expressions are the same:
#=: <Y>Example: <L:>./evidencer <0> -- -b<:>
#+: <Y>Example: <L:>./evidencer <0> -a -b<:>
#=: These two expressions are the same:
#=: <Y>Example: <L:>./evidencer <0> -- -k -w<:>
#+: <Y>Example: <L:>./evidencer <0> -a '-k -w'<:>
#+: <Y>Example: <L:>./evidencer <0> -a -k -a -w<:>

19 changes: 19 additions & 0 deletions extra/example_scripts/os.show.mem=+
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
ARG=$1
echo "ARG($ARG)"
PREALLOCATED=350000
if [ ! -z "$ARG" ];then
PREALLOCATED=$ARG
fi

echo "PREALLOCATED=$PREALLOCATED"
cat /proc/meminfo |grep MemTotal:
cat /proc/meminfo |grep MemTotal:|awk '{print $2}' |xargs -I{} echo "scale=1; ({}+$PREALLOCATED) / 1024/1024" |bc

#: Show the Linux Total amount of Memory.
#+: We've assumed that 350k of address space is snooped off by perifericals and BIOS/UEFI.
#+: You can override that value with a parameter
#=: <Y>Example: <L:>./evidencer <0>
#+: <Y>Example: <L:>./evidencer <0> -a 315000<:>

# https://serverfault.com/questions/1040981/how-much-physical-ram-is-lost-to-bios-uefi
6 changes: 6 additions & 0 deletions extra/example_scripts/os.show.uptime=+
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
uptime $@

#: Show the Linux uptime. Allows parameters.
#=: <Y>Example: <L:>./evidencer <0> -- -p<:>
#=: Shows only the update in human readable format.

0 comments on commit 202be51

Please sign in to comment.