Help needed on wrapper script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed on wrapper script
# 1  
Old 05-11-2014
Help needed on wrapper script

Hi Gurus,

I need to build a wrapper script which will be passing the loading date and the data file name (provides option to the user to load a single data file or load all the data files) to the actual loader data_load.ksh to load in the database.

1. I want to execute the loader script data_load.ksh one after another (one at a time), that is once data_load.ksh File1 finishes data_load.ksh File2 will start so and so forth. Loading a single file is not a concern. For full/all data files load, I am reading the data file names from a text file 'file.list' and executing the data_load.ksh from a for loop with an ampersand (sending to the background) & wait signal for each file, hoping that wait command will meet my expectation. Is there any alternate way of doing this?

2. My date validate part is not quite working as expected. Technically 20141411 date format should be incorrect but according to my date validation check echo ${dt}|grep -E -q '^201[1-9][01][0-9][0-3][0-9]$' it shows correct. How can I fix the MM part, so that any number other than 1 to 12 determines incorrect format?

3. In my fn_SingleFileLoad function, file name is passed through the input prompt. The input can not be more than one file name (i.e the program should send error or exit if someone provides more than one file. Example of an input: FileA FileB). Can someone please share some expertise on this part?

I would like to thank you all in advance for sharing your suggestions or help here.

Code:
#!/bin/ksh

###function for a complete data load  (i.e. all data files loading into database)
fn_AllFileLoad()
	{
           echo "enter the loadings date in YYYYMMDD format: "
           read dt
         
           # validates the date format
           echo ${dt}|grep -E -q '^201[1-9][01][0-9][0-3][0-9]$'
               if [[ $? != 0 ]]; then
                  echo "========================================================================="
         	  echo "Please enter the date in YYYYMMDD format. Terminating...No action done..."
         	  exit 1
               else
            
            	 .${HOME}/dbscripts/set_date.ksh $dt &
            	
 		for i in `cat ${HOME}/dbscripts/file.list`
                    do
            	    .${HOME}/dbscripts/data_load.ksh $i &
                    done
	            wait
         	fi
 
         }

fn_SingleFileLoad()
	 {
            echo "Enter the file name to load"
            read file
            echo "enter the loadings date in YYYYMMDD format: "
            read dt
        
            # validates the date format
            echo ${dt}|grep -E -q '^201[1-9][01][0-9][0-3][0-9]$'
                if [[ $? != 0 ]]; then
                   echo "========================================================================="
         	   echo "Please enter the date in YYYYMMDD format. Terminating...No action done..."
         	   exit 0
         	else
            
            	.${HOME}/dbscripts/set_date.ksh $dt &
            	.${HOME}/dbscripts/data_load.ksh $file & 
		fi
        }
 

#Main program starts here....

echo "Do you want to run a complete load? [Y/N]"
read yn
option=$yn
case $option in 
   Y|y ) fn_AllFileLoad;;
   N|n ) fn_SingleFileLoad;;
   * ) echo "Please answer only 'Y/y' for yes or 'N/n' for no.....terminating"
   exit;;
 esac

# 2  
Old 05-11-2014
Try changing:
Code:
'^201[1-9][01][0-9][0-3][0-9]$'

to:
Code:
'^201[1-9](0[1-9]|1[0-2])(0[[1-9]|[12][0-9]|3[01])$'

to allow months 01-12 and days 01-31. This will still incorrectly allow some days in short months (e.g., 20140230 and 20140431), but it won't allow days 00 and 32-39 nor months 00 and 13-19.

And, assuming that .${HOME}/dbscripts/data_load.ksh uses quotes properly and yields an appropriate diagnostic if its file operand isn't found, change:
Code:
.${HOME}/dbscripts/data_load.ksh $file&

to:
Code:
.${HOME}/dbscripts/data_load.ksh "$file" &

although I'm guessing that what you really wanted is:
Code:
. ${HOME}/dbscripts/data_load.ksh "$file" &

(Note the space added between the . and the$.)
# 3  
Old 05-11-2014
Thank you Don for your suggestions and reply. Yes, ill be run the files/directories in the each steps.

For #2 dateformat: It worked to resolve the month MM format. If I do not get solutions from anyone else for the shorter months, ill continue with the limitations.

to allow months 01-12 and days 01-31. This will still incorrectly allow some days in short months (e.g., 20140230 and 20140431), but it won't allow days 00 and 32-39 nor months 00 and 13-19.

For#3 - I need to allow only one file as an input and would like to through error & exit if multiple file names are entered. I am still not able figure that out. Any thoughts or suggestions will be great help.
# 4  
Old 05-11-2014
Once you have the format assured, you can verify the date with the cal command.
Code:
            echo "enter the loadings date in YYYYMMDD format: "
            read dt
       
            # validates the date format
            echo "$dt" | grep -E -q '^201[1-9](0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$'
            if [[ $? -ne 0 ]]; then
                   echo "========================================================================="
                   echo "Please enter the date in YYYYMMDD format. Terminating...No action done..."
                   exit
            else
                   year=${dt%????}
                   md=${dt#????}
                   month=${md%??}
                   day=${md#??}
                   cal $month $year | grep -q -w $((day))
                   if [[ $? -ne 0 ]]; then
                        echo "This date does not exist. Terminating...No action done." 
                        exit
                   else
                        .${HOME}/dbscripts/set_date.ksh $dt &
                        .${HOME}/dbscripts/data_load.ksh $file & 
                   fi
            fi

NB I have removed the double [ from the ERE that would allow a [ character in the input.
This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 05-11-2014
Thank you MadeInGermany! It works like a charm!

Now that I am close to my achievement, any idea how can I ensure #3 challenge.

For#3 - I need to allow only one file as an input and would like to through error & exit if multiple file names are entered. I am still not able figure that out. Any thoughts or suggestions will be great help.

Code:
echo "Enter the file name to load"
read file

# 6  
Old 05-12-2014
Since spaces, tabs, and filename pattern special characters are all legal characters in a filename, finding out if a string matches more than one filename is not as easy as it sounds. But trying to figure out that you have more than one filename doesn't make any sense; why not just verify that what you were given names an existing file? If you just want to know if $file does not expand to the name of a file of any type:
Code:
if [ ! -e "$file" ]
then    printf "No such file: \"%s\"\n" "$file"
        exit 1
fi

If you only want regular files, change -e to -f.
----------
And, I forgot to mention that you also need to change:
Code:
                        .${HOME}/dbscripts/data_load.ksh $file &

to:
Code:
                        .${HOME}/dbscripts/data_load.ksh "$file" &


Last edited by Don Cragun; 05-12-2014 at 03:34 AM.. Reason: Add additional required fix.
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 05-12-2014
Thank you Don for your help Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Wrapper for unix program - urgent help needed

Hello all , i need some help asap i have a program that keeps killing the machine when i did google searches and 2 days later i ran strace it seems the programm keeps making a system call to gettimeofday to i guess increment a counter ? gettimeofday({1347986584, 464904}, NULL) = 0... (6 Replies)
Discussion started by: NetworkLearning
6 Replies

2. Shell Programming and Scripting

problem with the my wrapper script

Hi friends, i am working in ksh88. i am running the follwing wapper script in background to run two jobs parallely((eg nohup wrapper.ksh &):: wrapper.ksh ######################## #!/bin/ksh nohup ./pii_insert.ksh /nsing83/p2/test & nohup ./pii_update.ksh... (1 Reply)
Discussion started by: neelmani
1 Replies

3. Shell Programming and Scripting

Wrapper Script in Perl Or shell

Hello, My requirement is based on Oracle where we run a perl script and it asked some questions.I want to write a wrapper which will answer all these questions. How is it possible. Thanks (16 Replies)
Discussion started by: cotton
16 Replies

4. UNIX for Advanced & Expert Users

Pass parameter to the main script from wrapper script

Hi, I am writing a wrapper script(wrap_script.sh) to one of the main scripts (main_script.sh) The main script is executed as following: ./main_script.sh <LIST> <STARTDATE> <ENDDATE> looks for a parameter which is a LIST(consists of different list names that need to be processed), START/END... (0 Replies)
Discussion started by: stunnerz_84
0 Replies

5. Shell Programming and Scripting

Count script wrapper help

I have this a code that I got help with for another task. I since tried to modify it to work on this task. I need someones expertise to modify it slightly and I am not sure where to start or yet fully understand the logic. I am trying to get a script to read my m-names.txt which has lots... (19 Replies)
Discussion started by: richsark
19 Replies

6. Shell Programming and Scripting

wrapper script in perl

Hi, I am in need of way to facilitate this senerio in a perl script. I have CLI ( command line interface) which I run like so: kip-tepltist -u Xxx -p Xxx Which produces tones of names from each template it found: 194Iselin-NJ 33-IDFLB-North-611-Woodward-8600 ... (5 Replies)
Discussion started by: richsark
5 Replies

7. Shell Programming and Scripting

Help with a wrapper script not working

Hello, I have the below wrapper script: #!/usr/bin/perl -w if ($^O eq 'MSWin32' ) { $subnet = 'c:\path\to\subnet.txt'; } else { $subnet = '/opt/qip/wrapper-del-sub'; } open FH1, 'jj-deleted-subnets.txt' or die "Can't open 'jj-deleted-subnets.txt' ... (0 Replies)
Discussion started by: richsark
0 Replies

8. Shell Programming and Scripting

Korn Shell Wrapper script

Hi Guys, I am trying write a wrapper script but I don't have any idea. I have 4 different korn shell scripts and all of them needs some parameters from command line (positional parameter). My script cant be interactive because its supposed to be automated. I am confused how can I write a wrapper... (6 Replies)
Discussion started by: pareshan
6 Replies

9. UNIX for Dummies Questions & Answers

What is a wrapper script

I tried searching the forum ,,but couldn't locate ..Can anyone give me a link or some information about wrapper script. (1 Reply)
Discussion started by: thana
1 Replies

10. UNIX for Dummies Questions & Answers

What is wrapper script and how to write

hi guys, I have a requirement to run a script 4 times with different parameter values. the 4 jobs have to run parallely which actually access different data of same table and deletes. how can i achieve this.................? Thanks in advance (1 Reply)
Discussion started by: chiru
1 Replies
Login or Register to Ask a Question