Register
It is currently Fri Oct 31, 2014 7:09 pm

Postgres controller script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Wed Jun 14, 2006 9:25 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
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




Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP