Jump to content

Linux Login Scripts


Cowboy Denny
 Share

Recommended Posts

So I ran into a gotcha the other day and so I figured it would be a good idea to capture it on our Tech Blog.

To make things easier we all use scripts to produce information as a user logs in.  Previously (years back) I followed some direction and added a shell script (login-info.sh) to /etc/profile.d since anything with the extension of .sh runs during login but that includes everybody.  Probably not a big deal until you try and run scp which then breaks since its running this script so you end up getting a protocol error and I believe its something to do with $TERM

Anyhow, more research I found this to be true in reference on where to place scripts

Scope Shell Script or directory to modify
User Bash ~/.bash_profile
User Bourne or Korn ~/.profile
User C (csh) ~/.login
Global (SystemWide) Bash /etc/profile
Global (All users except root) Bash /etc/profile.d
root Bash /root/.bash_profile

I originally had the following script under /etc/profile.d which prevented everyone from being able to utilize s

Then I removed the file from /etc/profile.d and I could use scp again

Decided to try and copy the contents of this file and paste at the end of /etc/profile which is assigned to all users (system wide) and I was working again and scp continues to work.

###### LOGIN SCRIPT ########
clear

#figlet -f slant $(hostnamectl --pretty)
echo " __   _ _______ _______ _  _  _  _____   ______ _     _    ";
echo " | \  | |______    |    |  |  | |     | |_____/ |____/     ";
echo " |  \_| |______    |    |__|__| |_____| |    \_ |    \_    ";
echo "                                                           ";
echo " _____ _     _ _______  _____       ______   _____  _     _";
echo "   |   |     | |  |  | |_____]      |_____] |     |  \___/ ";
echo " __|   |_____| |  |  | |            |_____] |_____| _/   \_";
echo "                                                           ";
printf "\n"
printf "\t- %s\n\t- Kernel %s\n" "$(cat /etc/redhat-release)" "$(uname -r)"
printf "\n"
echo " Welcome: $u"


date=`date`
load=`cat /proc/loadavg | awk '{print $1}'`
root_usage=`df -h / | awk '/\// {print $(NF-1)}'`
memory_usage=`free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { printf("%3.1f%%", used/total*100)}'`
swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", "exit !$2;$3/$2*100") }'`
users=`users | wc -w`
olusers=`who | cut -d' ' -f1 | sort | uniq`
time=`uptime | grep -ohe 'up .*' | sed 's/,/\ hours/g' | awk '{ printf $2" "$3 }'`
processes=`ps aux | wc -l`
ethup=$(ip -4 ad | grep 'state UP' | grep -v virbr0 | awk -F ":" '!/^[0-9]*: ?lo/ {print $2}')
ip=$(ip ad show dev $ethup |grep -v inet6 | grep inet|awk '{print $2}')

echo "System information as of: $date"
echo
printf "System load:\t%s\tIP Address:\t%s\n" $load $ip
printf "Memory usage:\t%s\tSystem uptime:\t%s\n" $memory_usage "$time"
printf "Usage on /:\t%s\tSwap usage:\t%s\n" $root_usage $swap_usage
printf "Local Users:\t%s\tProcesses:\t%s\n" $users $processes
echo "
=====================================================================
 - Users Logged on.....:
$olusers
=====================================================================
 - Users that need access to share files add them to the restricted group
 --> sftp user@10.11.24.11 (they are jailed to there home directory)
 -
=====================================================================
"
echo
[ -f /etc/motd.tail ] && cat /etc/motd.tail || true

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...