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
Prompting for Input - Getting Undefined Variable Kartheg UNIX for Dummies Questions & Answers 1 06-27-2007 06:24 PM
How to get variable input from a file maheshsri Shell Programming and Scripting 1 10-29-2005 08:26 AM
Perl: Variable input via HTML douknownam Shell Programming and Scripting 5 02-13-2005 11:39 PM
stupid question possibly MrJaunty Shell Programming and Scripting 1 10-03-2004 03:20 AM
please help: how to redirect input into a variable artur80 Shell Programming and Scripting 2 11-17-2002 10:18 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 07-04-2007
chadrt chadrt is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 3
input variable like POST in PHP possibly?

I have a very large database and once in awhile the database auto loading scripts that update the database for the daily updates fails and I have to go in and manually fix it but when that happens I usually have to start from scratch on sundays I have access to a weekly database rebuild. Then I have to apply each day thereafter to complete the process.

I have the weekly taken care of in a script that downloads the weekly update, unzips it, and uses some .sql scripts to load the information into the database. But I have 6 other scripts that have to be run one at a time for each of the days that may follow the weekly rebuild. What I am wanting to do is combine all 7 scripts into a single file say manual_rebuild.sh and then call that script with something like this:

./manual_rebuild.sh wed

The script would pick up that "wed" variable and it would download the weekly update unpack, load, delete the weekly .zip file then do monday, tuesday, and wednesday the same way. But I dont know how to define a variable like that from outside the script. If anyone has any clues please fill me in. Possibly a code example? Thank you...
  #2 (permalink)  
Old 07-04-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by chadrt View Post
But I dont know how to define a variable like that from outside the script.
To explicitly set a variable that will last for the scope of the script in sh, bash or ksh, do


Code:
WEEKDAY=wed ./manual_rebuild.sh

or to get a command line argument into a variable do this at start of script


Code:
#!/bin/sh
WEEKDAY=$1
...

  #3 (permalink)  
Old 07-05-2007
chadrt chadrt is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 3
Excellent, thank you very much the second one is what I was looking for! Just out of curiosity is it possible to have the script promt for the days to run like

Would you like to rebuild from last weeks major update? [yes/no]:

Would you like to add monday's update to the database? [yes/no]:

and it would carry out that set of instructions if you choose yes and if you choose no it would end the script.

That may be a little beyond the scope of a shell script but I am new at all this so the fact that I have written a script to do anything is amazing in itself. These scripts are my first attempts at any shell scripting. Thank again for the help...
  #4 (permalink)  
Old 07-05-2007
chadrt chadrt is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 3
Decided to do a little research on my own to try and figure this out I found a few things and this is what I have so far.


Code:
#!/bin/bash

echo -n "Would you like to rebuild DB from latest weekly?:"
read weekly
echo ""
echo You said $weekly
if [ $weekly = yes ] ; then
echo "This works!";

I get a small error about "unexpected end of file" but I think I am on the right track so far. I need figure out how I would do an ELSE. and then I can just put all my scripts in to one and use multiple sets of the above code, modified to work of course. Thanks for the assistance...
Closed Thread

Bookmarks

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 06:36 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