= Bash: Environment Script For Production and Acceptance =
**Summary**: A small script to warn users about in which environment they have logged on to. \\
**Date**: 22 March 2011 \\
**Refactor**: 6 April 2025: Checked links and formatting. \\
{{tag>bash aix}}
This is a script I use to warn users for the environment they work on. We have a lot of different environments and I like to take every opportunity to warn them about the environment, especially production. This is based on the hostname. I also use it to show a few specific thing, for example, where their system mails gets forwarded to. Below the script you'll find a section on how to set the script into action.
#!/bin/bash
########################################################################################################################
# Author : Sjoerd Hooft
# Date Initial Version: 22 March 2011
# Comments: sjoerd_getshifting.com
#
# Description:
# This is the script to warn about the environment where users login to.
#
# Recommendations:
# The script is designed for a 120 column terminal.
#
# Changes:
# Please comment on your changes to the script (your name and email address, line number, description):
########################################################################################################################
# Script Variables
BOLD=`tput bold`
BOLDOFF=`tput sgr0`
ENV=`hostname -s | awk -F- '{ print $2 }'`
MAIL=`cat $HOME/.forward`
if [ $ENV == prd ]; then
echo
echo "You have logged on to the ${BOLD}PRODUCTION ENVIRONMENT${BOLDOFF}. Be careful."
echo "You have logged on to the ${BOLD}PRODUCTION ENVIRONMENT${BOLDOFF}. Be very careful."
echo
echo "Your local mail is being forwarded to $MAIL"
echo "If this is wrong please change it in $HOME/.forward"
else
echo "You have logged on to the Acceptance environment"
fi
exit
= Script Usage =
To set the script into action add these lines to the /etc/profile file:
# Run the IT environment script
/opt/getshifting/scripts/environment.sh