Hi
I have a small bash script which I want to run on an Amazon EC2 Ubuntu instance for setting up a postgreSQL database:
#!/bin/bash
USERNAME='postgres'
start=$SECONDS
TMP_DIR=/local/test/4g4d
PORT=23456
rm -rf $TMP_DIR/db
mkdir -p $TMP_DIR/
echo "creating database..."
~/postgresql/bin/initdb -D $TMP_DIR/db
if [ $? -ne 0 ]
then
echo "Could not create the database"
fi
sed -i "s/#port = 5432/port = $PORT/" $TMP_DIR/db/postgresql.conf
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" $TMP_DIR/db/postgresql.conf
echo "host all all 0.0.0.0/0 md5" >> $TMP_DIR/db/pg_hba.conf
echo "starting postgresql server..."
~/postgresql/bin/pg_ctl -D $TMP_DIR/db -l $TMP_DIR/db/logfile start
if [ $? -ne 0 ]
then
echo "Could not start the postgresql server"
fi
sleep 10
echo "creating database..."
~/postgresql/bin/createdb -U $USERNAME -p $PORT asldb
echo "adding schema to database"
~/postgresql/bin/psql asldb -U $USERNAME -f ~/tpch/DBSetup.sql -p $PORT
end=$SECONDS
echo "Time: $((end - start)) secs."
hostname=`hostname`
pid=$$
while [ true ]
do
echo "writing log..."
echo `date +"%T"` >> who-$pid@$hostname.log
echo `date +"%T"` >> top-$pid@$hostname.log
echo `date +"%T"` >> ps-$pid@$hostname.log
who >> who-$pid@$hostname.log
top -n 1 -b >> top-$pid@$hostname.log
ps aux >> ps-$pid@$hostname.log
echo "" >> who-$pid@$hostname.log
echo "" >> top-$pid@$hostname.log
echo "" >> ps-$pid@$hostname.log
sleep 10
done
#read -p "Press any key to shutdown server."
# shut server down
#~/postgresql/bin/pg_ctl stop -D $TMP_DIR/db
# delete database
#rm -rf $TMP_DIR
Is this ok? How can I automatically install postgreSQL in a first step (apt-get install...)?
What exactly does the "writting log" loop at the end, i.e. what is logged and where exactly is the log saved?