The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pwd & cd commands not working in shell script perk_bud Shell Programming and Scripting 9 04-07-2008 08:11 AM
how to sql commands in shell script balireddy_77 Shell Programming and Scripting 1 11-15-2006 02:00 PM
how can I write script that lets me run shell commands? umen Shell Programming and Scripting 3 03-21-2006 08:33 AM
How to run unix commands in a new shell inside a shell script? hkapil Shell Programming and Scripting 2 01-04-2006 06:56 AM
how to execute shell commands in awk script? RishiPahuja Shell Programming and Scripting 1 09-02-2005 10:37 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-30-2007
perk_bud perk_bud is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 23
shell script to run a few commands help!

Hi friends this is first post i am very new to shell scripting so i require your expertise to do the following thank u

I need to write a shell script which will run the following commands

pg_dump bank > backup(Enter)
Wait for bash prompt to appear coz it indicates that the command is executed

dropdb bank(Enter)
Wait for bash prompt to appear coz it indicates that the command is executed

createdb bank(Enter)
Wait for bash prompt to appear coz it indicates that the command is executed

psql bank < backup(Enter)
Wait for bash prompt to appear coz it indicates that the command is executed

I need to run it as a cron demon plz also let me know how to put this as a cron so that it executes every time system starts Thanks in advance
  #2 (permalink)  
Old 07-03-2007
pbsrinivas pbsrinivas is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 141
U can Put all those in a file and give it Execute Permission

"Wait for bash prompt to appear coz it indicates that the command is executed" Only when a commond get executed it goes to the next command

And of Corntab

u can add an entry this way


@reboot run_script

where run_script is ur script...
  #3 (permalink)  
Old 07-03-2007
perk_bud perk_bud is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 23
First of all thanks

Quote:
Originally Posted by pbsrinivas View Post
U can Put all those in a file and give it Execute Permission


How do i do it
  #4 (permalink)  
Old 07-03-2007
pbsrinivas pbsrinivas is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 141
Quote:
Originally Posted by perk_bud View Post
First of all thanks

How do i do it
let me ask one question

what does ur "pg_dump bank > backup" do??

is pg_dump is a shell script with "bank" as command line arg... ??
  #5 (permalink)  
Old 07-03-2007
perk_bud perk_bud is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 23
a

"pg_dump bank > backup" takes the backup of the database which may take some time only after the process is complete can i run the run the next command that is "dropdb bank" which deletes the database.
  #6 (permalink)  
Old 07-03-2007
pbsrinivas pbsrinivas is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 141
Quote:
Originally Posted by perk_bud View Post
"pg_dump bank > backup" takes the backup of the database which may take some time only after the process is complete can i run the run the next command that is "dropdb bank" which deletes the database.

u can run all those on promt right??

u can do this

File run_script----

#! /bin/ksh
pg_dump bank > /input_path/backup
dropdb bank
createdb bank
psql bank < /input_path/backup


$chmod u+x run_script


$crontab -e
It Opens a file in that at the end give the following entry

@reboot /full_path_where_ur run_script_is_saved/run_script
  #7 (permalink)  
Old 07-03-2007
perk_bud perk_bud is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 23
"input_path" means where u want to take the backup right ?

Aneways thanx a bunch budy i'll try it out and let u know. 1 more thing i wanted to know about cron do i have to put my file in the cron.hourly or cron.daily folder or just crontab -e and do what u said and how do send myself an email from cron - the tasks the script has performed.
Closed Thread

Bookmarks

Tags
linux, sendmail

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0