Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cron jobs keeps time stamping

Status
Not open for further replies.

siswjh

MIS
Dec 6, 2001
63
US
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 &quot;.zip&quot;)
cd $HOME
for lines in $list
do
unzip $lines
mv $HOME/$lines $zipped
done
datname=$(ls -l $HOME|nawk '{print $9}'|grep -i &quot;.DAT&quot;)
for files in $datname
do
mv $files $files.orig
tr -d &quot;\015&quot; < $files.orig > $files
rm $files.orig
done
txtname=$(ls -l $HOME|nawk '{print $9}'|grep -i &quot;.txt&quot;)
for file in $txtname
do
mv $file $file.orig
tr -d &quot;\015&quot; < $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 &quot;There are new file(s) in the $HOME directory&quot; user@domain
else
print &quot;No new files&quot;
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
 
siswjh:

Yours is a long script; I took a quick look and nothing jumped out at me. One issue which probably has nothing to do with your problem, but your use of &quot;here&quot; documents in the ftp_files function:

Under the two unixes I use (SCO Open Server V and Solaris 7), I have a problem if the &quot;here&quot; terminator isn't in column one. The terminator isn't recoginized. If your script is working, you must not have that problem.

Regards,

Ed
 
Is the modification date changing or the access date changing?
An ls command against a file will change the access statmp. Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.

FREE Unix Scripts
 
Here is an ls -l from 14:20

-rw-r--r-- 1 root other 1544263 Apr 12 14:20 E01Q401.DAT
-rw-r--r-- 1 root other 0 Apr 12 14:20 filediff
-rwx------ 1 acbs acbsftp 4627 Apr 12 10:28 ftpacbs
-rw-r--r-- 1 root other 0 Apr 12 14:20 newfile
-rw-r--r-- 1 root other 55 Apr 12 14:20 oldfile
-rw-r--r-- 1 root other 0 Sep 25 2001 testfile


Then ten minutes later when the script runs again here is the ls -l again.

-rw-r--r-- 1 root other 1544263 Apr 12 14:30 E01Q401.DAT
-rw-r--r-- 1 root other 0 Apr 12 14:30 filediff
-rwx------ 1 acbs acbsftp 4627 Apr 12 10:28 ftpacbs
-rw-r--r-- 1 root other 0 Apr 12 14:30 newfile
-rw-r--r-- 1 root other 55 Apr 12 14:30 oldfile
-rw-r--r-- 1 root other 0 Sep 25 2001 testfile

 
The file E01Q401.DAT timestamp keeps changing. It shouldn't be. The other files yes because they are access by the script(filediff,oldfile,and newfile)each time it is run.
 
I would think that either a cp or ftp command
is updating the time stamp.

The best way to find this out is to put echo
or logging statements throughout each part of
of the script so that you know exactly
what the script is doing.

The script may be following a logic pattern
your are not aware of. Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.

FREE Unix Scripts
 
The system had some qurkie problems at the beginning of the week where the /bin to /usr/bin link would just disappear I think I have fixed that problem, but when I wrote these scripts the shell I'm using is /bin/ksh, don't know it that's something. Just tried changing to /usr/bin/ksh still the same thing. These scripts needless to say have been working fine for the last six months when I first started this project. The last modification I did was in late Febuary, and that was just unziping and removing the ^M's.

Jesse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top