sh [记录SSH会话(高级)]尝试向脚本添加一些项目,因此创建一个新条目#bash

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh [记录SSH会话(高级)]尝试向脚本添加一些项目,因此创建一个新条目#bash相关的知识,希望对你有一定的参考价值。

#!/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"

以上是关于sh [记录SSH会话(高级)]尝试向脚本添加一些项目,因此创建一个新条目#bash的主要内容,如果未能解决你的问题,请参考以下文章

在 powershell ssh 会话中访问 Windows 网络驱动器

通过 SSH 执行存储在文件中的 Bash 脚本

jenkins会话问题

sh ssh-pass:使用密码存储中的密码短语向您的代理添加SSH密钥,无需剪贴板

Linux用sh脚本为ssh添加ip黑名单-CentOS 7.0

如何使用 ssh 在后台运行命令并分离会话