I have some ftp scripts that run through cron. The script goes to a directory and checks for new files and if there are none it kill's itself. The scripts run every ten minutes. The problem is that it touchs these files some how and I not sure how. This just started happening. They, the scripts have been in place for over six months working fine. Does anyone have any clues.
Thanks in advance
Jesse
Here is the script
#!/bin/ksh
###############################################################################
# Written by: Jesse Hardy September 18, 2001 #
# This script will take files from Berlin and ftp them to Detroit #
###############################################################################
###############################################################################
# Setting up some variables #
###############################################################################
FTP="/usr/bin/ftp -i"
HOME="/b/00/acbs/incenprd/tocmg"
DHOME="/hdgstg01/applr11i/common/incenprd/incoming"
CHO="/usr/bin/chown"
CHG="/usr/bin/chgrp"
CAT="/usr/bin/cat"
MV="/usr/bin/mv"
COMM="/usr/bin/comm"
CP="/usr/bin/cp"
zipped="/b/01/zipped"
orig="/b/01/orig"
###############################################################################
# This function was added on December 6, 2001. The function was added because #
# the users decided that they wanted to be able to transfer multiple files. #
# The takes whatever new files are in the the specified directory and ftp's #
# them to the staging area on another server #
###############################################################################
function ftp_files
{
$FTP detroit <<-END
ascii
lcd $HOME
cd $DHOME
put $file
quit
END
}
###############################################################################
# This procedure was added on Febuary 26, 2002. The procedure checks all new #
# files to see if they are zipped and if they are will unzip the files. Then #
# it checks the file that has been unzipped for ^M (don't you just hate Micro-#
# soft) if ^M's are found it removes them. #
###############################################################################
list=$(ls -l $HOME|nawk '{print $9}'|grep -i ".zip"
cd $HOME
for lines in $list
do
unzip $lines
mv $HOME/$lines $zipped
done
datname=$(ls -l $HOME|nawk '{print $9}'|grep -i ".DAT"
for files in $datname
do
mv $files $files.orig
tr -d "\015" < $files.orig > $files
rm $files.orig
done
txtname=$(ls -l $HOME|nawk '{print $9}'|grep -i ".txt"
for file in $txtname
do
mv $file $file.orig
tr -d "\015" < $file.orig > $file
rm $file.orig
done
###############################################################################
# This control statement will go to the home directory and list the contents #
# of that directory and will compare the contents of that listing with the #
# contents of the comparison file. It will also move whatever is different #
# to a holding file handle for later manipulation #
###############################################################################
cd $HOME
ls -l|nawk '{print $9}' > newfile
if [[ -f $HOME/oldfile && -f $HOME/newfile ]]
then
difffile=$($COMM -3 oldfile newfile)
fi
###############################################################################
# I had to move this out of the control statement because I couldn't assign #
# the output of the comm command to a variable and a file at the same time. #
###############################################################################
cd $HOME
$COMM -3 oldfile newfile > filediff
$CP $HOME/newfile $HOME/oldfile
> newfile
###############################################################################
# This control statement checks for the existance of the filediff file and if #
# it is there is it empty, if it is empty prints no new files if it is not #
# empty then it emails Dominick that there is a new file in the directory #
###############################################################################
if [[ -f $HOME/filediff && -s $HOME/filediff ]]
then
$CAT $HOME/filediff|mailx -s "There are new file(s) in the $HOME directory" user@domain
else
print "No new files"
fi
################################################################################
# This control statement will check $difffile to see if it is empty if it is it#
# will kill the script if not it will ftp file(s) #
################################################################################
if [[ -z $difffile ]]
then
kill $$
fi
cd $HOME
#################################################################################
# This for loop looks at the variable $difffile and the names of the files that #
# it holds. It then calls the function ftp_files and ftp's whatever files are #
# in the variable #
#################################################################################
for file in $difffile
do
ftp_files
done
Thanks in advance
Jesse
Here is the script
#!/bin/ksh
###############################################################################
# Written by: Jesse Hardy September 18, 2001 #
# This script will take files from Berlin and ftp them to Detroit #
###############################################################################
###############################################################################
# Setting up some variables #
###############################################################################
FTP="/usr/bin/ftp -i"
HOME="/b/00/acbs/incenprd/tocmg"
DHOME="/hdgstg01/applr11i/common/incenprd/incoming"
CHO="/usr/bin/chown"
CHG="/usr/bin/chgrp"
CAT="/usr/bin/cat"
MV="/usr/bin/mv"
COMM="/usr/bin/comm"
CP="/usr/bin/cp"
zipped="/b/01/zipped"
orig="/b/01/orig"
###############################################################################
# This function was added on December 6, 2001. The function was added because #
# the users decided that they wanted to be able to transfer multiple files. #
# The takes whatever new files are in the the specified directory and ftp's #
# them to the staging area on another server #
###############################################################################
function ftp_files
{
$FTP detroit <<-END
ascii
lcd $HOME
cd $DHOME
put $file
quit
END
}
###############################################################################
# This procedure was added on Febuary 26, 2002. The procedure checks all new #
# files to see if they are zipped and if they are will unzip the files. Then #
# it checks the file that has been unzipped for ^M (don't you just hate Micro-#
# soft) if ^M's are found it removes them. #
###############################################################################
list=$(ls -l $HOME|nawk '{print $9}'|grep -i ".zip"
cd $HOME
for lines in $list
do
unzip $lines
mv $HOME/$lines $zipped
done
datname=$(ls -l $HOME|nawk '{print $9}'|grep -i ".DAT"
for files in $datname
do
mv $files $files.orig
tr -d "\015" < $files.orig > $files
rm $files.orig
done
txtname=$(ls -l $HOME|nawk '{print $9}'|grep -i ".txt"
for file in $txtname
do
mv $file $file.orig
tr -d "\015" < $file.orig > $file
rm $file.orig
done
###############################################################################
# This control statement will go to the home directory and list the contents #
# of that directory and will compare the contents of that listing with the #
# contents of the comparison file. It will also move whatever is different #
# to a holding file handle for later manipulation #
###############################################################################
cd $HOME
ls -l|nawk '{print $9}' > newfile
if [[ -f $HOME/oldfile && -f $HOME/newfile ]]
then
difffile=$($COMM -3 oldfile newfile)
fi
###############################################################################
# I had to move this out of the control statement because I couldn't assign #
# the output of the comm command to a variable and a file at the same time. #
###############################################################################
cd $HOME
$COMM -3 oldfile newfile > filediff
$CP $HOME/newfile $HOME/oldfile
> newfile
###############################################################################
# This control statement checks for the existance of the filediff file and if #
# it is there is it empty, if it is empty prints no new files if it is not #
# empty then it emails Dominick that there is a new file in the directory #
###############################################################################
if [[ -f $HOME/filediff && -s $HOME/filediff ]]
then
$CAT $HOME/filediff|mailx -s "There are new file(s) in the $HOME directory" user@domain
else
print "No new files"
fi
################################################################################
# This control statement will check $difffile to see if it is empty if it is it#
# will kill the script if not it will ftp file(s) #
################################################################################
if [[ -z $difffile ]]
then
kill $$
fi
cd $HOME
#################################################################################
# This for loop looks at the variable $difffile and the names of the files that #
# it holds. It then calls the function ftp_files and ftp's whatever files are #
# in the variable #
#################################################################################
for file in $difffile
do
ftp_files
done