Page MenuHomeDevCentral

whom-diff.sh
No OneTemporary

whom-diff.sh

#!/bin/sh
# -------------------------------------------------------------
# whom-diff
#
# Computes the diff between two `whom` invoke.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Author: Sébastien Santoro aka Dereckson
# Created: 2015-12-30
# Licence: BSD-2-Clause
# Source file: roles/shellserver/user-session/files/whom-diff.sh
# -------------------------------------------------------------
#
# <auto-generated>
# This file is managed by our rOPS SaltStack repository.
#
# Changes to this file may cause incorrect behavior
# and will be lost if the state is redeployed.
# </auto-generated>
# -------------------------------------------------------------
# Determines session identifier and directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$SESSION_ID" = "" ]; then
SESSION_ID=$(who am I | md5 | cut -c1-8)
fi
DIR=/var/tmp/whom/$USER/$SESSION_ID
# -------------------------------------------------------------
# -s / --session
# Prints the session identifier
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$1" = "--session" ] || [ "$1" = "-s" ]; then
echo "$SESSION_ID"
exit 0
fi
# -------------------------------------------------------------
# Default mode
# Prints the diff between current `whom` and previous output
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ $# -eq 0 ]; then
# Creates working directory if needed
if [ ! -d "$DIR" ]; then
mkdir -p "$DIR"
touch "$DIR"/old
fi
# Let's diff
cd "$DIR" || exit
whom > current
diff old current | tail -n +2
mv current old
exit 0
fi
# -------------------------------------------------------------
# -c / --clean
# Cleans directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$1" = "--clean" ] || [ "$1" = "-c" ]; then
rm -rf "$DIR"
exit $?
fi
# -------------------------------------------------------------
# Usage
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>&2 echo "Usage: $0 [--setup|--clean|-s|-c]"
exit 1

File Metadata

Mime Type
text/x-shellscript
Expires
Sat, Oct 11, 20:05 (4 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3059770
Default Alt Text
whom-diff.sh (2 KB)

Event Timeline