Last active
November 12, 2017 21:00
-
-
Save veritas06/a7d9deb6de4f1af7d9cadc3da9ce134f to your computer and use it in GitHub Desktop.
[Log SSH Session (Advanced)] Trying to add some items to the script, so making a new entry #bash
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 | |
# ------------------------------------------------------------------ | |
# Sean P. McAdam: SSH Session Logging | |
# Script to log each SSH session | |
# ------------------------------------------------------------------ | |
VERSION=0.2.0 | |
SUBJECT=tech.v3ritas.log_ssh_adv | |
USAGE="Usage: log_ssh_adv -ivhc username destinationHost" | |
CHANGELOG="20171112-1545: Corrections to parameters." | |
# --- Options processing ------------------------------------------- | |
if [ $# == 0 ]; then | |
echo $USAGE | |
exit 1; | |
fi | |
while getopts ":i:vhc" optname | |
do | |
case "$optname" in | |
"v") | |
echo "Version $VERSION" | |
exit 0; | |
;; | |
"i") | |
echo "-i argument: $OPTARG" | |
;; | |
"h") | |
echo $USAGE | |
exit 0; | |
;; | |
"?") | |
echo "Unknown option $OPTARG" | |
exit 0; | |
;; | |
"c") | |
echo $CHANGELOG | |
exit 0; | |
;; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
param1=$1 | |
param2=$2 | |
# $LogDirectory="/home/$USER/Logs/" | |
# if [ ! -d "$LogDirectory" ]; then | |
if [ ! -d "/home/$USER/Logs" ]; then | |
# mkdir "/home/$USER/Logs" | |
echo "Log directory not detected. Being created at /home/$USER/Logs." | |
mkdir "/home/$USER/Logs" | |
fi | |
# if [ "$1" == "-h" ]; then | |
# echo "Usage: `log_ssh USERNAME HOST`" | |
# exit 0 | |
# fi | |
echo "User:" $1 | tee -a "/home/$USER/Logs/SSH.log" | |
echo "Host:" $2 | tee -a "/home/$USER/Logs/SSH.log" | |
echo "Log directory detected at /home/$USER/Logs." | |
date | tee -a "/home/$USER/Logs/SSH.log"; ssh "$1"@"$2" | tee -a "/home/$USER/Logs/SSH.log" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment