1) I have to create 3 scripts which create different output files. Script one creates datafiles, script2 creates control files and script3 creates flg files. The business wants the same timestamp to be attached to all the files created by these scripts.
Script1- Create data files - Data files name format-> xxxx.01122010_223048.dat
Script2- Create Control files - Control files name format -> yyyy.01122010_223048.ctl
Script3 - Create flg files- flg files name format-> zzzz.01122010_223048.flg
How can I define a variable which gives the timestamp once and then can be used in all the three scripts?
These scripts are called from an intial script as follows
./$POS_SCRIPT/dw_postodw_pharmacysplit.ksh
./$POS_SCRIPT/dw_postodw_controlfile.ksh
./$POS_SCRIPT/dw_postodw_cpfiles.ksh
How do I check the return status of the previous script before starting the next If the return status is not success, I need to write that to a logfile and exit in the succeeding scripts.
-----------------------------------------
2)I have an input file(named common_files) which contains a set of table names. I need to search the current directory to check if the filename contain the table names from the input file. Move all those files to another directory.
For example the filename is of the format XXXX_<tablename>_timestamp. If the tablename matches from input file, those files should be moved to another directory.
Can I do the grep and move with a single command in my scripting? I got stuckup as below.
if [[ -s common_files]]
then
while read line
do
'grep -l $line * | mv
done <common_files
fi
[LEFT]--------------------------------------
3)I have another input file which contains a list of pharmacyids(This is an input file contains around 450 pharmacy ids). I need to search a set of flatfiles(119 files) to split them based on the 450 ids.Means each of these 119 files need to be split into 450 files based on the presence of the pharmacy ids. The postion of pharmacy id in the 119 files vary from file
to file.I need to search for the id as a whole word and copy the matching lines to outputfiles. So a maximum of 119 * 450 output files may be generated.[/LEFT]
INPUT FILE -> a file contains a list of 450 pharmacyids
flat FILE -> 119 files whcih may conatin the 450 pharmacy ids , but position of ids vary
OUTPUT FILES->the files created from flat files by copying the matching lines for each id.
The below one is my script. Can somebody review and give suggestions on logic and performance?(I heard 'cat' and grep used together will slow down the performance especially this may be executed 119 * 450 times).
for pharmacyf in `ls`
do
$tablename=` $pharmacyf | cut �f3 -d'.' `
while read pharmacyid
do
cat $pharmacyf | grep -w $pharmacyid >> $POSOUT/ODS.POS.$pharmacyid.$tablename.$CURRENT_DATE
done<inputfile
done
Thanks
Maya
