Customize the Login and Logout on NetBSD
I like to customize the login with a different last login notification and a Daily Dose of Wisdom delivered courtesy of fortune(6) piped to cowsay.
Hush
Quiet the default output after logging into the system by creating an empty .hushlogin
file:
$ touch ~/.hushlogin
Last Login
View the list of all logins, reboots, and shutdowns with the last(1) command:
$ last
Display at login the who/when/duration of the last login by modifying .profile
:
$ vi ~/.profile
Add:
# Last user login
last | head -10 > /tmp/recentlogins; \
sed -i.bak '/boot/d;/shutdown/d;/reboot/d;/tmux/d' /tmp/recentlogins; \
cat /tmp/recentlogins | head -2 | tail -1 | \
awk '{ ORS=""; print "Last login: " $1 " on " $2; $1=$2=""; print $0 }'; echo ""
Save changes and exit.
Daily Dose of Wisdom
Install:
# pkgin install fortune cowsay
Command fortune
prints an adage chosen at random from database files stored in /usr/pkg/share/games/fortune
. Run:
$ fortune
I'll defend to the death your right to say that, but I never said I'd
listen to it!
-- Tom Galloway with apologies to Voltaire
List the fortune files installed:
$ fortune -f
100.00% /usr/pkg/share/games/fortune
...
Now to make my own fortune(s)!
NOTE
Be careful not to duplicate a file name from the above list outputted by fortune -f
.
I create a file containing bits of wisdom I collect from all over:
$ vi dailyDoseOfWisdom
Add blocks of text separated by the %
percent sign. Sample:
Barn's burnt down / now I can see the moon.
-- Mizuta Masahide
%
To belittle, you have to be little.
-- Kahill Gibran, The Prophet
%
If you don’t get everything you want, think of the things you don’t get
that you don’t want.
-- Oscar Wilde
%
Save changes and exit.
Convert this file to a format that fortune
can use with the strfile(8) command, which generates the necessary *.dat
file type:
$ strfile -c % dailyDoseOfWisdom dailyDoseOfWisdom.dat
Copy both files to the fortune
data location:
# cp dailyDoseOfWisdom* /usr/pkg/share/games/fortune/
Get your wisdom straight from the cow:
$ fortune dailyDoseOfWisdom | cowsay
_________________________________________
/ If you don’t get everything you want, \
| think of the things you don’t get |
| that you don’t want. |
| |
\ -- Oscar Wilde /
-----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
To display at login my cow-ified fortunes, modify .profile
:
$ vi ~/.profile
Add:
# Daily dose of wisdom
myfortune="/usr/pkg/share/games/fortune/dailyDoseOfWisdom"
if command -v fortune 2>&1 >/dev/null
then
if command -v cowsay 2>&1 >/dev/null && [ -f "$myfortune" ]
then
fortune $myfortune | cowsay
else
fortune
fi
fi
Save changes and exit.
Clear Terminal at Logout
Here is a method that works in all modern shells (I'm using ksh
).
Add to ~/.profile
:
test -f $HOME/.exitrc && trap ". $HOME/.exitrc" EXIT
Create ~/.exitrc
with:
echo "type clear >/dev/null 2>&1 && clear" > ~/.exitrc
See: https://unix.stackexchange.com/a/12013
You can like, share, or comment on this post on the Fediverse 💬
« Previous: Configure SSH on NetBSD for Passwordless Logins to Servers