[2025-jun-17] The SlackDocs mailing lists at https://lists.alienbase.nl/mailman/listinfo have been retired. No one has been using these lists for years and it's time to say goodbye. The list archives remain available at https://scalzi.slackware.nl/mailman/listinfo/slackdocs

[2025-jun-17] The SlackDocs Wiki has moved to a new server, in order to make it more performant.

Welcome to the Slackware Documentation Project

Slackware Login Message with Fortune and Cowsay

tl;dr — Display a random fortune message and last login information on interactive login shells using Slackware's native /etc/profile.d/ mechanism. Easy to enable, easy to disable.

Overview

This document describes a simple and reversible method to enhance the Slackware login experience by displaying a random fortune message using cowsay, along with information about the last user login.

The setup uses Slackware's native /etc/profile.d/ mechanism and applies only to interactive login shells.

Design goals

  • use Slackware-native mechanisms
  • avoid background services or hooks
  • affect only interactive login shells
  • remain easy to disable or remove
  • preserve a clean and predictable login process

Assumptions

  • Slackware 15.0 or Slackware -current is in use
  • bsd-games is installed (provides fortune)
  • cowsay is installed
  • a Bourne-compatible login shell is used (sh, bash, etc.)
  • the user has root access

Required packages

The fortune program is provided by bsd-games:

# slackpkg install bsd-games

The cowsay package is available on SlackBuilds.org. Download the build script, then as root:

# lftp -c "open https://slackbuilds.org/slackbuilds/15.0/games/; mirror cowsay"
# cd cowsay
# sudo sh cowsay.SlackBuild
# sudo installpkg /tmp/cowsay-*.t?z

Profile script setup

Create the following file as root:

/etc/profile.d/fortune-cowsay.sh

Add the following content:

#!/bin/sh
#
# Display last login information and a fortune message on
# interactive login shells.
#
 
# Do nothing if hushlogin exists
if [ -e "$HOME/.hushlogin" ]; then
    return
fi
 
# Only run for interactive shells
case $- in
*i*)
    echo
 
    # Display last user login (ignore shutdown/reboot entries)
    last -n 10 | grep -vE 'shutdown|reboot' | head -n 1 | \
    awk '{ORS=""; print "Last login: " $1 " on " $2; $1=$2=""; print $0}' && echo ""
 
    echo
 
    if command -v cowsay >/dev/null 2>&1; then
        fortune fortunes fortunes2 linuxcookie | cowsay
    else
        fortune fortunes fortunes2 linuxcookie
    fi
 
    echo
    ;;
esac

Make the script executable:

# chmod +x /etc/profile.d/fortune-cowsay.sh

Disabling the default fortune message

Slackware's bsd-games package installs its own login fortune scripts in /etc/profile.d/. To avoid duplicate output, disable them:

# chmod -x /etc/profile.d/bsd-games-login-fortune.sh
# chmod -x /etc/profile.d/bsd-games-login-fortune.csh

Verification

Log in as a user with an interactive shell or start a new login session:

$ su -l username

You should see:

  • a “Last login” line (excluding reboot and shutdown entries)
  • a random fortune displayed via cowsay (if installed)

Example output

A typical login may display output similar to the following:

Last login: user on pts/0 Mon May  5 22:01:45 2025

 _______________________________________
/ You will be attacked by a beast with \
\ big teeth. Film at 11.               /
 ---------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Suppressing the message per user

To disable the login message for a specific user, create an empty file in their home directory:

$ touch ~/.hushlogin

This follows standard Unix behavior and requires no further changes to the system configuration.

Notes

  • If cowsay is not installed, only the fortune message is displayed
  • The script affects login shells only
  • Non-interactive shells are not impacted
  • The script can be disabled system-wide at any time with chmod -x

Conclusion

Using /etc/profile.d/ to display a fortune and login information is a clean and idiomatic way to customize Slackware's login environment.

This approach adds personality without sacrificing simplicity, predictability, or control, and can be disabled at any time with minimal effort.

References

Sources

* Originally written by r1w1s1

QR Code
QR Code howtos:misc:slackware_cowsay (generated for current page)