In my suse install, I created a link to my script ...... i created the script under the username crouse, but root has to run it. I created a .bashrc file for root and linked the command
pgc to
alias pgc='/home/crouse/scripts/postgres/pgc.sh'
and of course made the script executable.....
chmod a+x /home/crouse/scripts/postgres/pgc.sh
Looks like this when run :
Code:
*****************************************************
* POSTGRES CONTROLLER *
* Postgres is currently running. *
*****************************************************
1)Start Postgres 2)Stop Postgres 0)Exit
Please choose one of the options above :
Code:
#!/bin/bash
#
##########################
# USA Linux Users Group #
# http://www.usalug.org #
# http://bashscripts.org #
##########################
#######################################################
# Postgres Controller
#######################################################
#
#
# FILE: pgc.sh
# VERSION: 1.0
# DATE: 06-09-2006
#
# AUTHOR: Crouse - Please visit bashscripts.org and usalug.org
#
#
########################################################
# A controller for starting and stopping postgres
############## VARIABLES ##############
POSTGRESSERVER=/usr/local/pgsql/bin/postmaster
PGCONTROL=/usr/local/pgsql/bin/pg_ctl
PGDATAFILES=/usr/local/pgsql/data
LOGFILE=/usr/local/pgsql/data/postmaster.log
############## END OF VARIABLES ##############
############## FUNCTIONS #############
#Notes the "-i" option after the server allows connection of remote clients
checkforroot ()
{
ROOT_UID=0
if [ "$UID" -ne "$ROOT_UID" ]
then
echo ""
echo "**************** ERROR !! **************"
echo "You must be logged in as root to run this script"
echo "Please log in as root and re-run this script."
echo "**************** ERROR !! **************"
exit
fi
}
STARTPOSTGRES ()
{
su -l postgres -c "nohup ${POSTGRESSERVER} -D ${PGDATAFILES} >${LOGFILE} 2>1 &"
read -p "Hit any key to continue. " temp
mainmenu
}
STOPPOSTGRES ()
{
su -l postgres -c "${PGCONTROL} -D ${PGDATAFILES} stop"
read -p "Hit any key to continue. " temp
mainmenu
}
pgstatusis ()
{
file=/usr/local/pgsql/data/postmaster.pid
if [[ -e $file ]]
then
pgstatus="running."
else
pgstatus="stopped."
fi
}
headerfile ()
{
clear;
echo "*****************************************************";
echo "* POSTGRES CONTROLLER *";
echo "* Postgres is currently ${pgstatus} *";
echo "*****************************************************";
}
mainmenu ()
{
pgstatusis
headerfile
menu=" 1)Start Postgres 2)Stop Postgres 0)Exit"
while true; do
headerfile;
echo -e "$menu"
echo "";
read -p "Please choose one of the options above : " option
case $option in
1) STARTPOSTGRES; ;;
2) STOPPOSTGRES; ;;
0) exit; ;;
*) echo "Sorry, that isn't an option, try again. "; sleep 2; ;;
esac
done;
}
############## END OF FUNCTIONS #############
############## PROGRAM RUN STARTS HERE ##############
checkforroot
mainmenu
exit