Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Script to pick the files from source folder Post 302595585 by Vijay81 on Friday 3rd of February 2012 01:19:53 PM
Old 02-03-2012
Script to pick the files from source folder

Hi,

I wrote a script to pick files based on some logic. when I execute my script, I get the below message ( I bolded the lines in the script where this error message shows up), it says that files are not available and it is a valid scenario if the files are not available and I don't know how to get rid of this message.. I am guessing this is a warning not an error as my script continues after this message..can someone help me on how to get rid of this message?

Message:

ls: FERAL_DATA_*_20121213.FERAL_DAT.TXT: No such file or directory
ls: FERAL_CONTROL_20121213.FERAL_CTRL.TXT: No such file or directory

below is my script..as I am new to unix scripting, I have posted the script to get suggestions from experts.. like I may missed something.. or could have done it in a better way.. please help me!


PHP Code:
# pickdate_paramfile1.sh
###script to pick the files based on the date of run and generate a parameter file #####
#!/bin/sh
. /opt/informatica/infa_shared/SCRIPTS/env_file.ksh
date_str
=`date "+%Y%m%d%H%M%S"`
ENVID=$1
logfile
=$LOGS/${ENVID}_pickupdate_${date_str}.log
echo Script $0 started at `date` >${logfile}
#### Check if one parameter is received#######
if [ $# -ne 1 ]; then
echo "input parameter for the script is missing" >>${logfile2>&1
exit 1
fi
######Connect to DB to fetch the date of run#####
DATE_OF_RUN_DB=`sqlplus -s <<sqlEOF
$ORACLE_USERNAME/$ORACLE_PASSWORD@$ORACLE_DB
set feedback off
set heading off
set linesize 5000
set pagesize 0
set echo off
whenever sqlerror exit failure
whenever oserror exit failure
SELECT TO_CHAR(MAX(LAST_RUN_DATE) +1,'YYYYMMDD') FROM ENV_LOAD_HISTORY WHERE ENV_ID='
$ENVID' AND STATUS_OF_RUN ='SUCCESS';
sqlEOF
`
if [ $? -
ne 0 ]; then
echo "error connecting to database" >>${logfile}
exit 
1
fi
#######If DATE_OF_RUN_DB is empty throw message and abend the script
if  [ -"$DATE_OF_RUN_DB]
then
echo "No date of run value fetched from DB" >>${logfile2>&1
exit 1
fi
echo "Date of run fetched from DB is - $DATE_OF_RUN_DB>>${logfile}
####Get the files based on the date received from the DB#####
cd $SOURCE_FOLDER
Data_Files
=`ls ${ENVID}_DATA_*_${DATE_OF_RUN_DB}.${ENVID}_DAT.TXT`
control_file=`ls ${ENVID}_CONTROL_${DATE_OF_RUN_DB}.${ENVID}_CTRL.TXT`
#####if control file is not available for that date then look for the files with the least date value in the landing folder and decide the date of run#####
if  [ -"${control_file}]
then
echo "Control File is missing for date $DATE_OF_RUN_DB>>${logfile2>&1
cd $SOURCE_FOLDER
Actual_Date
=`ls ${ENVID}_CONTROL_*.${ENVID}_CTRL.TXT| sort -t"_" -k3.8 | head -1 | cut -d"_" -f3| cut -d"." -f1`
####pick files based on the date value
Data_Files_New=`ls $SOURCE_FOLDER/${ENVID}_DATA_*_${Actual_Date}.${ENVID}_DAT.TXT`
control_file_New=`ls $SOURCE_FOLDER/${ENVID}_CONTROL_${Actual_Date}.${ENVID}_CTRL.TXT`
##### if no files for that date then throw error message and notify via email & abend the script
if  [ -"${Data_Files_New}--"${control_file_New}"  ]
then
echo "Files are missing for date $Actual_Date>>${logfile2>&1
#### include email notification script#####
exit 1
fi
DATE_OF_RUN
=${Actual_Date}
CONTROL_FILE_FINAL=${control_file_New}
echo 
"Files are $Data_Files_New $control_file_New>>${logfile}
cp ${Data_Files_New} ${control_file_New$WORK
if [ $? -ne 0 ]; then
echo "Files are not copied" >>${logfile}
exit 
1
else echo "Files are copied to work directory" >>${logfile}
fi
else
DATE_OF_RUN=${DATE_OF_RUN_DB}
CONTROL_FILE_FINAL=${control_file}
echo 
"Files are $Data_Files $control_file>>${logfile}
cp ${Data_Files} ${control_file$WORK
if [ $? -ne 0 ]; then
echo "Files are not copied" >>${logfile}
exit 
1
else
echo 
"Files are copied to work directory" >>${logfile}
fi
fi
echo "date of run = $DATE_OF_RUN>>${logfile2>&1
echo "Control file name is $CONTROL_FILE_FINAL>>${logfile2>&1
#######If DATE_OF_RUN is empty throw message and abend the script
if  [ -"${DATE_OF_RUN}]
then
echo "No date of run value fetched unable to proceed" >>${logfile2>&1
exit 1
fi
######Create a workflow parameter file#####
parmfile=$PARM_FILES/${ENVID}_parm.parm
parmfile1
=$PARM_FILES/${ENVID}_PARM_I.TXT
##### Check if <EOF> tag is available in control file####
if [ `tail -1 "$CONTROL_FILE_FINAL"` = "<EOF>" ]
then echo "<EOF> tag is available in the $CONTROL_FILE_FINAL>>${logfile2>&1
#####copy contents from control file to parameter file####
touch ${parmfile}
cd $SOURCE_FOLDER
cp $CONTROL_FILE_FINAL $parmfile1
sed 
'$d' $parmfile1 $parmfile
rm $parmfile1
echo "DATE_OF_RUN=$DATE_OF_RUN>>${parmfile}
echo 
"ENVID=$ENVID>>${parmfile}
echo 
"parameter file created is $parmfile"  >>${logfile}
else  echo 
"<EOF> tag missing in $CONTROL_FILE_FINAL>>${logfile2>&1
exit 1
fi 

Last edited by Vijay81; 02-03-2012 at 02:57 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Suppres error message when moving files from empty source folder

Hi, I would like to write a shell script that moves files from one folder to another without retrieving the error 'can not acces/find file or folder' when the source folder is empty. Any ideas, Thx in advance, Steven. (2 Replies)
Discussion started by: Steven
2 Replies

2. Shell Programming and Scripting

Script to pick out files from a file which are older than 15 days

Hi , I have a file abc.txt which actually contains a directory and file list -rwxrwxr-x 1 dmadmin mmasapp 334 Dec 03 2001 aafs_006.ksh -rwxrwxr-x 1 dmadmin mmasapp 1270 Nov 13 2001 mcl_deposit_ftp.ksh -rwxrwxr-x 1 dmadmin mmasapp 925 Oct 31 2001 ... (1 Reply)
Discussion started by: viv1
1 Replies

3. Shell Programming and Scripting

script for Finding files in a folder and copying to another folder

Hi all, I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt. I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Discussion started by: satish2712
5 Replies

4. Shell Programming and Scripting

Running a script with all files in a folder

Hi I have many files in a folder (like 200) and I want to run a Perl script through all of them. One way would be to do it one by one (which will take forever). But I am sure there is a faster way of doing it. So inside the folder i have files named in no particular way eg. YUI456... (3 Replies)
Discussion started by: phil_heath
3 Replies

5. UNIX for Dummies Questions & Answers

Script for checking the files in a folder

Hi , I am using the below script for checking for a file in a folder. if ; then echo 0 else echo 1 fi Is there any way we can check for files which are starting with GL*.csv.What I am trying to do is , I have to check in a folder for the GL*.csv files if there are any files they I... (6 Replies)
Discussion started by: wangkc
6 Replies

6. Shell Programming and Scripting

Need script using cp to transfer files to another folder

Hi guys , how are you doing? I am tryng to make a script using cp that i would like to do this: echo "Enter the name files to tranfer" then user has to enter via keyboard this kind of output file1 file 2 file 3 file x (i mean the number of the files could vary and their name too)... (1 Reply)
Discussion started by: REX:)
1 Replies

7. Shell Programming and Scripting

need a shell script to extract the files from source file and check whether those files existonserve

Hi, I am new to shell scripting.Please help me on this.I am using solaris 10 OS and shell i am using is # echo $0 -sh My requirement is i have source file say makefile.I need to extract files with extensions (.c |.cxx |.h |.hxx |.sc) from the makefile.after doing so i need to check whether... (13 Replies)
Discussion started by: muraliinfy04
13 Replies

8. Shell Programming and Scripting

Pick files after specified Time from a folder in Perl

Hi All I am stuck in a problem and wants help What i want to do is I have a directory(say name of that directory is outdir) In that directory(outdir) the files come after some gap of time by some processes. What i want to do is i want to list all the files in that directory after the given... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

9. UNIX for Dummies Questions & Answers

Script to delete files in different folder

Hi Experts, i need a little help. i have different folder that contain files that need to be deleted. but those folder contains huge amoung of same with 3 different extention. what i used to do is to delete them using the rm commande rm *.ext *.ext1 *.ext3 what i want to do is to have... (1 Reply)
Discussion started by: yprudent
1 Replies

10. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies
All times are GMT -4. The time now is 05:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy