look for a contracthead file first and if the contract head file does not exist on day1 exit script.
Now on day2 if contracthead exists or not run the script uploading files in order
such as contract line then contract contact
so the whole order on day1 is
contracthead
contractline
contractcontact
on day2
if it exists or not run the script like the order above even if files are missing.
Now this is the script i came up with.
basically the if statement for the days block seems not be working
it works determinig day 1 and 2 but it does nto run the script as i want it to.
So far.g if it has a contracthead ont he first day and no days file.
It will upload contract head and go to the else statement and create the days file. It should not do this because the contracthead file exists. If it did not exist then the days file will be created.
Could you tell me where i am going wrong please.
Code:
Code:
#!/bin/bash
# DATE varaible is used to archive the files after ftp
DATE=`/bin/date +%Y%m%d%H%M`
# TODIR variable is the target directory for the file on remote system 32x
TOARCHIVEDIR=/home/tibco/tibco/archive
# 32x
TODIR=/home/tibco/tibco/AIS_FTP/test/inbound/Staging
# FROMDIR variable is the source directory of the file on the local system 5x
FROMDIR=/home/tibco/ems/FTP/test/inbound/Staging/FTPComplete
# ARCHDIR variable is the directory file get moved to after tranfer 5x
ARCHDIR=/home/tibco/archive/testFtp2_32X
pwd=`pwd`
echo $pwd
cd $FROMDIR
STEXT="The following files were received in: /home/tibco/ems/FTP/test/inbound/Staging/FTPComplete \n"
ETEXT="The following files were NOT FOUND in: /home/tibco/ems/FTP/test/inbound/Staging/FTPComplete \n"
########Running Loop########
for file in int_sap_contracthead*.txt
int_sap_contractline*.txt
int_sap_contractcontact_*.txt
do
echo $file
if [ -f $file ]
then
#echo " file $file exists"
STEXT="%10s $STEXT \n $file "
#echo " $STEXT "
else
ETEXT="%10s $ETEXT \n $file "
#echo " $STEXT "
fi
done
SUCCESS=`printf "$STEXT " `
FAIL=`printf "$ETEXT " `
##################### Checkign if the days file exists######################
NF=Contracthead file not found
NFEMAIL=Contracthead file not found
if [ -e "days" ]
then
echo "*** The days file exists ***"
rm days
echo "*** removing the days file ***"
echo " ------ This is day 2 - all files are loading ------ "\n\n\n
################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contracthead_*.txt
bye
EOF
############ END FTP ###############
echo "*** -- UPLOADING FILE CONTRACTHEAD -- ***"
sleep 8
elif [ -e "int_sap_contracthead_*.txt" ]
then
echo "*** -- UPLOADING FTP -- ***"
################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contracthead_*.txt
bye
EOF
############ END FTP ###############
echo "int_sap_contracthead_*.txt File is uploading"
else
echo "1" > days
echo "Files will not upload today"
exit
fi
sleep 8
##################### End##################
echo "code still running"
if [ "$file" = "int_sap_contractline*.txt" ]
then
################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contractline_*.txt
bye
EOF
############ END FTP ###############
echo "contracthead File is uploading"
sleep 8
else
echo "there is NO contractcontact File to upload"
fi
if [ "$file" = "int_sap_contractcontact*.txt" ]
then
################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contractcontact_*.txt
bye
EOF
############ END FTP ###############
echo "contractcontact File is uploading"
else echo "there is NO contractcontact File to upload"
fi
HEADER="FTP Summary of the files "
mail -s "$HEADER" test@domain.com <<EOF
$SUCCESS
$FAIL
EOF
# create the archive directory based on timestamp and move files
cd $ARCHDIR
mkdir $DATE
mv $FROMDIR/int_sap_contractline_*.txt $ARCHDIR/$DATE/
mv $FROMDIR/int_sap_contractcontact $ARCHDIR/$DATE/
mv $FROMDIR/int_sap_contracthead_*.txt $ARCHDIR/$DATE/
exit
You are testing for the existence of a file with an asterisk truly in the filename. Removing the quotes will make it work provided there is exactly one matching file name.
elif ls int_sap_contracthead_*.txt >/dev/null 2>&1
will work with many names.
if [ "$file" = "int_sap_contractline*.txt" ]
also not gonna fly. Double brackets would work if you unquote the pattern. Or use a case statement.
Hello,
I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this :
This is the output of ls command : I stored the output in a file filelist
1.1M... (5 Replies)
Hi,
I am having a shell Script which i need to modify. I am new to shell scripting , needs help. The Logic which needs to be incorporated is as follows :-
The script need to check the length of first Line in a data fine and of the length of the file is > 130 then validated the input... (2 Replies)
Hello,
i have below shell script to process ftp get from server and create file list afte finish.
this shell scipt has 6 parameter input.
unfortunately, it is only working to get the file and terminated before creating file list.
please help.
thanks,
#!/bin/ksh
## example usage :... (3 Replies)
Hi,
My objective is to make a shell script that, when run, you can input multiple links at once.
text is then inserted between the http:// part and the following url.
example : http://google.be ==> http://sometext.google.be
it would be great if it could then open all the created links (wich... (5 Replies)
I want to use an awk for the following scenario but not sure if it will work or not. I have two input file: F1 and F2
F1
02
05
08
F2
00
01
02
03
04
05
06
07
08
09
10 (1 Reply)
Hi GURU's,
I'm using a Shell Script to send email's as an attachment.
I'm Storing the email address in a table and catching in a variable.
MAILLIST=`noarg sqlplus -s $OraUsr << EOF
set heading off
set feedback off
set echo off
SELECT email_ids
FROM tpemail_table
WHERE... (9 Replies)
The following script is meant to check the presence of a file - called filename0.94.tar.gz - and uncompress it:
#!/bin/sh
# check presence of file
VERSION=0.94
if ; then
# file not present: abort
echo "Files cannot be found."
#exit 1 (commented out this line, so we can see how the... (2 Replies)
Ok, So up front I'm going to say that I'm a very elementary scripter, and I tend to use tools I don't fully understand, but I shotgun at something until I can get it to work...that said, I can't for the life of me understand why I can't get this to go down the way I want it to.
The goal:
-to... (6 Replies)
Hi All,
I am new to Shell scripting.
I have a log file containing XML Messages.Each XML Message is accompanied with a timestamp.I need to count the the number of messages that get logged in a particular timeinterval.Is there any command/Syntax to achieve this.
Any code/example is... (5 Replies)