shell script to run a few commands help!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to run a few commands help!
# 15  
Old 07-03-2007
u have to connect to ur plsql to do th pg_dump

thats y i asked u what does pg_dump do???

and i said "u can run all those on promt right??"

u have not replied for those...

do u run pg_dump after logging on to plsql????
# 16  
Old 07-03-2007
no i'll tell u normally this is how i do it i iniate a telnet session using windows run command

it asks me for a login : postgres

after which it does not ask for password as no password is required and it shows the bash prompt where i execute the following command pg_dump

Now i dont think psql comes into the picture anywhere
# 17  
Old 07-03-2007
Quote:
Originally Posted by perk_bud
no i'll tell u normally this is how i do it i iniate a telnet session using windows run command

it asks me for a login : postgres

after which it does not ask for password as no password is required and it shows the bash prompt where i execute the following command pg_dump

Now i dont think psql comes into the picture anywhere


then y these in picture..

PGUSER=postgres
PGPASSWORD=""
export PGUSER PGPASSWORD


and instead of sendmail u can use mail in linux
echo "BackUp Done"| mail parikshit@belgaum.tbdnet (For this to run ur SMTP should be configured as ur sending to external system)
# 18  
Old 07-03-2007
This is an example script which works perfectly and executes the command "pg_dump" even though the mentioned password is wrong

----------------------------------------------------------------------------
#!/bin/sh
##############################
#Script by Anas V
##############################

#Substitute your postgresql root username in the below given line
PGUSER=postgres
#Substitute your postgresql root password in the below given line
#PGPASSWORD=mypostgre
PGPASSWORD=pearls
export PGUSER PGPASSWORD

tdate=`date +%d-%b-%Y`

if [ $# -lt 1 ]

# Check if there is atleast one argument [i.e the database whose dump is to be taken]
#First argument is mandatory - Databse name
#Second argument is optional - Destination path to save dump
then

echo "Bad Arguments"
echo "-----------------------------------"
echo "USAGE : pg_dmp.sh <databasename> [outputfile]"
echo "-----------------------------------"
exit 1
else

#if one or more arguments were provided
if [ $# -ge 2 ]
#if arguments provided is greater than or equal to 2
then
#Comment out the below given file exist check and it's associated messages
# if you want to run the pg_dmpsh script to run silently. i.e from a cron or at job
# without any user interaction. Then the output dump file will be rewritten if a file
# already exists.
if [ -f $2 ]
# if destination file ie argument 2 is already existing
then
#Show confirmation message to confirm whether replace file with new one or exit
dialog --title "Confirm File Replace" --backtitle "pg_dmp.sh"\
--yesno "\nFile already exist, Do you want to replace it with '$2' file" 7 90
sel=$?
case $sel in
#if Yes then take dump and replace the existing file with new dump
0) pg_dump $1 -f $2 -i -x -O -R;;
#if No then exit
1) exit 1 ;;
#if escape then exit
255) exit 1;;
esac
else
#if destination file does not exist then create and save the dump in destination path
pg_dump $1 -f $2 -i -x -O -R
fi
else
if [ $# -eq 1 ]
#if arguments provided is equal to 1
then
if [ -d $HOME/pg_backup_$1 ]
#if folder name pg_backup_'databsename' exist in the current users home directory
then
if [ -f $HOME/pg_backup_$1/$1_$tdate ]
#if destination file name exist in pg_backup_'databasename' folder in current users home dierectory
then
#Show confirmation message for replacing the file with new dump
dialog --title "Confirm File Replace" --backtitle "pg_dump.sh"\
--yesno "\nFile already exist, Do you want to replace it with '$HOME/pg_backup_$1/$1_$tdate' file" 7 90
sel=$?
case $sel in
#if Yes then replace the file with new dump file
0) pg_dump $1 -f $HOME/pg_backup_$1/$1_$tdate -i -x -O -R;;
#if No then exit
1) exit 1 ;;
#if escape thenexit
255) exit 1;;
esac
else
#if destination file does not exist then create and save the dump
pg_dump $1 -f $HOME/pg_backup_$1/$1_$tdate -i -x -O -R
fi
else
#if folder pg_backup_'databsename' does not exist in the current users home dierectory then
#Create a new folder
mkdir $HOME/pg_backup_$1
#then create dump and save it
pg_dump $1 -f $HOME/pg_backup_$1/$1_$tdate -i -x -O -R
#if databse to take does not exist then Delete the folder created
if [ $? -ne 0 ]
then
rmdir $HOME/pg_backup_$1
fi
fi
fi
fi
if [ $# -gt 2 ]
#if arguments passed where greater than 2 then show message
then
echo "Extra Arguments ignored"
fi
fi

#reset PGUSER and PGPASSWORD
PGUSER=""
PGPASSWORD=""
export PGUSER PGPASSWORD
#End
# 19  
Old 07-03-2007
I dont know i'm getting an error in my script which is almost the same! As u can see in the above example they are entering the username and password that i think that is necessary.
# 20  
Old 07-03-2007
Quote:
Originally Posted by perk_bud
I dont know i'm getting an error in my script which is almost the same! As u can see in the above example they are entering the username and password that i think that is necessary.
ok lets try this..

just put

pg_dump bank backup

in u.sh and run
tell me what happens..
# 21  
Old 07-03-2007
I'm really sorry

PGUSER=postgres
PGPASSWORD=""
export PGUSER PGPASSWORD

is not required now the "pg_dump bank > backup" command works but the "dropdb bank" command does not work it says "this database does not exist"

But when i execute the same @ bash it works fine.

Wonder what could be the probs ANY WAY THANKS A BUNCH BUDDY FOR STAYING WITH ME
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run Shell Commands after creating MYSQL Connection

Hi, I am trying to make a Shell Script using which I will update around 10K records in MySQL db each night. For that, I am currently doing the following command in FOR LOOP: mysql -D $MASTER_DB_NAME -h $MASTER_DB_HOST -u $MASTER_DB_USER -p$MASTER_DB_PASSWD -e "$SQL_Query" This command is... (2 Replies)
Discussion started by: rahulmittal87
2 Replies

2. UNIX for Dummies Questions & Answers

Commands to run from shell script

Hi script> isumid 98765432 if i give above command in cmd prompt it is running the same thing if i give inside the shell script it is not working below is the code #!/bin/bash isumid 98765432 please give me a solution (16 Replies)
Discussion started by: Ramrangasamy
16 Replies

3. Shell Programming and Scripting

shell script to run commands in different terminals

hi, how to write shell script that runs different commands(like:ls,ps,ls-l) in differnt terminals(each command should run in different terminal). my main motive is to run different 'c' program exe's available in different locations in different terminals. thanks sai (2 Replies)
Discussion started by: saidopdf
2 Replies

4. Shell Programming and Scripting

[bash] run a shell who runs commands

Hi all. On X11 I'm on a shell ...shell_1 (/bin/bash). From here I want to open another shell window shell_2 who executes commands like "ls -l" or programs like ". /program"... so the "result" of commands shows in shell_2 window and not in shell_1. Is that possible ? (4 Replies)
Discussion started by: jerold
4 Replies

5. Shell Programming and Scripting

Run Shell Commands via HTML on a client machine

Hi guys, so, I have a server running an sqlite database which is accessed by many client machines working as hardware testers, whenever something fails and needs to be replaced the operator would have to enter the Serial Number of the part being replaced as well as some other data. and... (0 Replies)
Discussion started by: sx3v1l_1n51de
0 Replies

6. Shell Programming and Scripting

Run multiple commands in $() without opening a new shell

The code below works, but takes too many lines and looks awkward: db2 "export to $filename of del select * from $table with ur"|tee -a $LOGFILE|awk '/Number of rows exported:/ {print $5}' > numrows.tmp numrows=$(cat numrows.tmp) rm numrows.tmp When I try the... (2 Replies)
Discussion started by: akar_naveen
2 Replies

7. Shell Programming and Scripting

Help with shell script to run the commands reading options from local file

I have to use shell script to run series of commands on another unix box by connecting through SSH and giving user credentials. For running commands on remote machine I have to use options reading from a local file. Process: Connecting to remote unix server <host1.ibm.com> through ssh Login: ... (2 Replies)
Discussion started by: itsprout
2 Replies

8. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

9. Shell Programming and Scripting

how can I write script that lets me run shell commands?

Hello I want to make simple extension to vi , you know how you want to run some shell command you do ":! ls -l " , then you go out the vi the command executed and then you hit enter and you back to vi but now I want to be able to go out of vi and run several command outside of vi .. and in... (3 Replies)
Discussion started by: umen
3 Replies

10. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
Login or Register to Ask a Question