You are not logged in.

#1 2012-06-11 09:58:24

ojko
Member
Registered: 2012-04-18
Posts: 1

Execute a dynamic ssh banner and motd

I have made a dynamic ssh banner and motd script, but am not sure what the best way is to run this script. Is there any way to run a script when a user connects via ssh, that will have permissions to write to /etc/...?

Also can you use colour codes in the ssh banner? It appears to be displaying the colour codes rather than changing the colour.

#!/bin/bash
USER=`whoami`
HOSTNAME=`uname -n`
PACMAN=`pacman -Qu | wc -l`
DISC=`df -h | grep rootfs | awk '{print $5 }'`
MEMORY1=`free -t -m | grep "buffers/cache" | awk '{print $3" MB";}'`
MEMORY2=`free -t -m | grep "Mem" | awk '{print $2" MB";}'`
PSA=`ps -Afl | wc -l`
PSU=`ps U $USER h | wc -l`

# time of day
HOUR=$(date +"%H")
if [ $HOUR -lt 12  -a $HOUR -ge 0 ]
then 	TIME="morning"
elif [ $HOUR -lt 17 -a $HOUR -ge 12 ] 
then 	TIME="afternoon"
else 
	TIME="evening"
fi

#System uptime
uptime=`cat /proc/uptime | cut -f1 -d.`
upDays=$((uptime/60/60/24))
upHours=$((uptime/60/60%24))
upMins=$((uptime/60%60))
upSecs=$((uptime%60))

#System load
LOAD1=`cat /proc/loadavg | awk {'print $1'}`
LOAD5=`cat /proc/loadavg | awk {'print $2'}`
LOAD15=`cat /proc/loadavg | awk {'print $3'}`

echo "
[H[2J
        [1;36m.[1;37m
       [1;36m/#\[1;37m                     _     [1;36m _ _                  
      [1;36m/###\[1;37m      __ _ _ __ ___| |__  [1;36m| (_)_ __  _   ___  __
     [1;36m/#####\[1;37m    / _' | '__/ __| '_ \ [1;36m| | | '_ \| | | \ \/ /
    [1;36m/##.-.##\[1;37m  | (_| | | | (__| | | |[1;36m| | | | | | |_| |>  < 
   [1;36m/##(   )##\[1;37m  \__,_|_|  \___|_| |_|[1;36m|_|_|_| |_|\__,_/_/\_\\
  [1;36m/#.--   --.#\[1;37m
 [1;36m/'           '\[0m

Good $TIME $USER, you are attempting to log onto $HOSTNAME 
 " > /etc/issue_ssh
# " > ~/Documents/issue_ssh

echo "
[H[2J
*************************************************************************
 - HOSTNAME                  =   $HOSTNAME
 - KERNEL                    =   `uname -r`
 - ARCH                      =   `uname -m`
 - SYSTEM		     =   $PACMAN packages can be updated
 - USERS		     =   Currently `users | wc -w` users logged on
*************************************************************************
 - Current User		     =	 $USER
 - CPU Usage		     =   $LOAD1 1 min $LOAD5 5 min $LOAD15 15 min
 - CPU Temperature	     =   `acpi -t | cut -f4 -d' '` C
 - Memory Used	             =   $MEMORY1 / $MEMORY2
 - Swap in use               =   `free -m | tail -n 1 | awk '{print $3}'` MB
 - Processes		     =   You are running $PSU of $PSA processes
 - System Uptime             =   $upDays days $upHours hours $upMins minutes $upSecs seconds
 - Disk Space Used           =   $DISC
*************************************************************************
 " > /etc/motd
# " > ~/Documents/motd

Last edited by ojko (2012-07-20 18:38:32)

Offline

#2 2015-12-13 15:50:10

shearsey
Member
Registered: 2015-12-13
Posts: 1

Re: Execute a dynamic ssh banner and motd

I know this is a bit old now but I used this original as the basis for my login banner and tweaked it to make the colours codes work, hopefully someone (if not the OP) will find it useful

#!/bin/bash

#clear
PROCCOUNT=`ps -Afl | wc -l`
PROCCOUNT=`expr $PROCCOUNT - 5`
GROUPZ=`groups`

if [[ $GROUPZ == *irc* ]]; then
ENDSESSION=`cat /etc/security/limits.conf | grep "@irc" | grep maxlogins | awk {'print $4'}`
PRIVLAGED="IRC Account"
else
ENDSESSION="Unlimited"
PRIVLAGED="Regular User"
fi

echo -e "
\e[1;34m
        /#\ \e[1;37m                    _      \e[1;34m  _ _
       /###\ \e[1;37m     __ _ _ __ ___| |__   \e[1;34m | (_)_ __  _   ___  __
      /#####\ \e[1;37m   / _' | '__/ __| '_ \  \e[1;34m | | | '_ \| | | \ \/ /
     /##.-.##\ \e[1;37m | (_| | | | (__| | | | \e[1;34m | | | | | | |_| |>  <
    /##(   )##\ \e[1;37m \__,_|_|  \___|_| |_| \e[1;34m |_|_|_| |_|\__,_/_/\_\\
   /#.--   --.#\ \e[1;34m
  /'           '\ \e[1;37m


\e[1;35m+++++++++++++++++: \e[1;37mSystem Data\e[1;35m :+++++++++++++++++++
+  \e[1;37mHostname \e[1;35m= \e[1;32m`hostname`
\e[1;35m+   \e[1;37mAddress \e[1;35m= \e[1;32m`ifconfig  | grep 'inet'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $2}'`
\e[1;35m+    \e[1;37mKernel \e[1;35m= \e[1;32m`uname -r`
\e[1;35m+    \e[1;37mUptime \e[1;35m= \e[1;32m`uptime | sed 's/.*up ([^,]*), .*/1/' | sed -e 's/^[ \t]*//'`
\e[1;35m+       \e[1;37mCPU \e[1;35m= \e[1;32m`lscpu | grep 'Model name:' | cut -d: -f2 |awk '{print $0}' | sed -e 's/^[ \t]*//'`
\e[1;35m+    \e[1;37mMemory \e[1;35m= \e[1;32m`cat /proc/meminfo | grep MemTotal | awk {'print $2'}` kB
\e[1;35m++++++++++++++++++: \e[1;37mUser Data\e[1;35m :++++++++++++++++++++
\e[1;35m+  \e[1;37mUsername \e[1;35m= \e[1;32m`whoami`
\e[1;35m+ \e[1;37mPrivlages \e[1;35m= \e[1;32m$PRIVLAGED
\e[1;35m+  \e[1;37mSessions \e[1;35m= \e[1;32m`who | grep $USER | wc -l` of $ENDSESSION MAX
\e[1;35m+ \e[1;37mProcesses \e[1;35m= \e[1;32m$PROCCOUNT of `ulimit -u` MAX
\e[1;35m+++++++++++++++++++++++++++++++++++++++++++++++++++
"

Offline

Board footer

Powered by FluxBB