Article 51EC3 [SOLVED] profile.d hack for non-login shells

[SOLVED] profile.d hack for non-login shells

by
rwyarbrough
from LinuxQuestions.org on (#51EC3)
I was googling for a way to make my logins match and consistent between login shells and non login shells for my desktop systems. For my server systems, it really isn't a issue (for me anyways) however on those machines where I also fire up XWindows I like having the shell environments the same.

After searching, I couldn't really find any solutions, so I tried matching shell behavior between non-login and login shells by setting a LOGIN_HEADER environment variable as a "bit" to indicate I've already gone through the /etc/profile.d scripts once so I don't duplicate the effort in the users .bashrc. For some reason that doesn't work for Konsole logins as the very first initial login to the system does go through /etc/profile.d and Konsole never goes through the /etc/profile.d scripts.

Here is what I tried first -

I have a file named 00-header.sh in my /etc/profile.d that looks like this:

Code:#!/bin/sh
#
# 00-header - create the header of the MOTD
CPUTYPE=$(cat /proc/cpuinfo | grep 'model name' | head -1 | cut -d':' -f2)
CPUTYPEINTEL=$(echo $CPUTYPE | grep -i intel)
if [ "$CPUTYPEINTEL" = "" ]
then
CPUSPEED=$(lscpu |awk -F : '($1=="CPU max MHz") {printf "%3.2fGHz\n", $2/1000}')
CPUINFO=$(echo "$CPUTYPE @ $CPUSPEED")
else
CPUINFO=$CPUTYPE
fi
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo -e "\e[1;32mWelcome to `cat /etc/slackware-version` on $(uname -n)"
echo "CPU: `echo $CPUINFO` with `grep -c ^processor /proc/cpuinfo 2>/dev/null` cores"
echo "Kernel: $(uname -r) Arch: $(uname -m) Bogomips: `awk -F: '/bogomips/ {sum+=$2} END {print sum}' /proc/cpuinfo`"
echo "Compiled: $(uname -v | cut -d' ' -f 3-6,8)"
echo "Boot Time: $(uptime -s) $(uptime -p)"
echo -e "External IP Address: $(curl -s checkip.amazonaws.com)\e[0m"
# set env variable to pass to users .bashrc
LOGIN_HEADER="/etc/profile.d/00-header.sh"
export LOGIN_HEADERthen for the users individual .bashrc file I have this code at the end:

Code:# test to see if we have already gone through the /etc/profile.d scripts once - if not execute /etc/profile.d scripts
if [ -z "$LOGIN_HEADER" ]
then
# Append any additional sh scripts found in /etc/profile.d/:
for profile_script in /etc/profile.d/*.sh ; do
if [ -x $profile_script ]; then
. $profile_script
fi
done
unset profile_script
unset LOGIN_HEADER
fithat didn't work - the goal is to get a consistent experience no matter if I ssh into the box or use the local logins. I really don't want to move the /etc/profile.d scripts to each individual user as that breaks the distribution default behavior, but so far that is what it is looking like the answer to be - Please if anyone has a better way than moving everything to the users .bashrc would be much appreciated.

Thoughts?

Thankslatest?d=yIl2AUoC8zA latest?i=6bvC6xbZzFY:3E_y7wCT4KE:F7zBnMy latest?i=6bvC6xbZzFY:3E_y7wCT4KE:V_sGLiP latest?d=qj6IDK7rITs latest?i=6bvC6xbZzFY:3E_y7wCT4KE:gIN9vFw6bvC6xbZzFY
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments