Compare file timestamp with current date. Diff must be 1 hour.

Hello,

I've created the script below to compare the content of two files with a delay of an hour. After an hour, the lines that exist in both files, will be printed and executed.

The script now uses a counter to countdown 50 minutes. But what I would prefer is to check the file timestamp of the first file, and then compare it with the second file. Once the difference is 50 minutes or more, then the files have to be compared based on their content and execute the lines that exist in both files.

I tried to use the "find -mmin" command, but find doesn't know the mmin parameter (HP-UX beryl B.11.11 U 9000/800).

I've found a lot of information on this forum already, so I hope someone can help me out! Thanks!

 
export SQL_DIR=/opt/staffware/server/sql
export LOG_DIR=/opt/staffware/server/logs
export BIN_DIR=/opt/staffware/server/bin
export ORA_BIN_DIR=/opt/oracle/ora817/bin
export ORACLE_HOME=/opt/oracle/ora817
 
SID=
USER=
PASSWD=
 
OUTPUTFILE1=sw_locked_cases_check_1.txt
OUTPUTFILE2=sw_locked_cases_check_2.txt
SORTEDOUTPUTFILE1=sw_locked_cases_check_1s.txt
SORTEDOUTPUTFILE2=sw_locked_cases_check_2s.txt
FINALOUTPUTFILE=sw_locked_cases_checked.txt
 
# Teller in minuten
COUNTDOWN=50
# --------------------------------------------------------------------
 
# Controle of de juiste persoon is ingelogd
echo "Script gestart op `date`"
echo "Je bent ingelogd als `whoami`";
if [ `whoami` != "swadmin" ]; then
echo "Je dient als swadmin ingelogd te zijn om dit script te starten."
exit
fi
 
# Maak outputfiles aan
cat <<EOF >$BIN_DIR/$OUTPUTFILE1
EOF
cat <<EOF >$BIN_DIR/$OUTPUTFILE2
EOF
cat <<EOF >$BIN_DIR/$FINALOUTPUTFILE
EOF
 
# voer SQL query uit - check 1
$ORA_BIN_DIR/sqlplus -s $USER/$PASSWD@$SID <<!>$BIN_DIR/$OUTPUTFILE1
whenever sqlerror exit 2
set heading off
set pages 0
set feedback off
set verify off
SELECT 'swutil UNLOCKMAIL ' || o_queuename || ' ' || o_reqid || ':sw_nimbus_prd01'
FROM staffo
WHERE o_locker IS NOT NULL
ORDER BY O_QUEUENAME
/
!
 
# gebruik countdown variabele om de lengte van de sleep te bepalen
echo
while [[ ${COUNTDOWN} -ge 0 ]]
do
echo "Nog" ${COUNTDOWN} "minuten totdat het script verder gaat."
sleep 60
COUNTDOWN=$(( ${COUNTDOWN} - 1 ))
done
 
# voer SQL query uit - check 2
echo
$ORA_BIN_DIR/sqlplus -s $USER/$PASSWD@$SID <<!>$BIN_DIR/$OUTPUTFILE2
whenever sqlerror exit 2
set heading off
set pages 0
set feedback off
set verify off
SELECT 'swutil UNLOCKMAIL ' || o_queuename || ' ' || o_reqid || ':sw_nimbus_prd01'
FROM staffo
WHERE o_locker IS NOT NULL
ORDER BY O_QUEUENAME
/
!
 
# voer een compare uit
sort $BIN_DIR/$OUTPUTFILE1 > $BIN_DIR/$SORTEDOUTPUTFILE1
sort $BIN_DIR/$OUTPUTFILE2 > $BIN_DIR/$SORTEDOUTPUTFILE2
comm -12 $BIN_DIR/$SORTEDOUTPUTFILE1 $BIN_DIR/$SORTEDOUTPUTFILE2 > $FINALOUTPUTFILE
 
# voer iedere regel in de finaloutputfile uit
while read LINEFROMFILE
do
print `$BIN_DIR/$LINEFROMFILE` "$LINEFROMFILE"
# echo $LINEFROMFILE
done < $BIN_DIR/$FINALOUTPUTFILE
 
echo
OF1=`ls -ltr $OUTPUTFILE1 | awk '{print $8}'` 
OF2=`ls -ltr $OUTPUTFILE2 | awk '{print $8}'` 
#OF2=`date +%R`
echo "Leeftijd controlebestand 1" $OF1
echo "Leeftijd controlebestand 2" $OF2
 
# verwijder de finaloutputfile
echo
echo "Tijdelijke bestanden worden verwijderd." 
rm -rf $BIN_DIR/$OUTPUTFILE1
rm -rf $BIN_DIR/$OUTPUTFILE2
rm -rf $BIN_DIR/$SORTEDOUTPUTFILE1
rm -rf $BIN_DIR/$SORTEDOUTPUTFILE2
rm -rf $BIN_DIR/$FINALOUTPUTFILE

Why are you exporting these variables?

There's no need for cat:

> "$BIN_DIR/$OUTPUTFILE1"
> "$BIN_DIR/$OUTPUTFILE2"
> "$BIN_DIR/$FINALOUTPUTFILE"

Why are you calling rm 5 times?

rm -rf "$BIN_DIR/$OUTPUTFILE1" "$BIN_DIR/$OUTPUTFILE2" "$BIN_DIR/$SORTEDOUTPUTFILE1" \
       "$BIN_DIR/$SORTEDOUTPUTFILE2" "$BIN_DIR/$FINALOUTPUTFILE"

Most of your script has nothing to do with the question you asked.

## difftime by Chris F.A. Johnson
## Created Fri Dec 29 03:09:25 EST 2006
## Copyright 2006 Chris F.A. Johnson
## This script is released under the terms of
## the GNU General Public Licence, Version 3

version=0.2

if [ $# -ne 2 ]
then
  cat <<-EOF

	   difftime - calculate sub-second difference between two times

	   USAGE: difftime MM:SS.Frac MM:SS.Frac

	EOF
  exit
fi

awk  -v begin="$1" -v end="$2" 'BEGIN {
   split ( begin, t1, ":" )
   split ( end, t2, ":" )
   d2 = 60 * t2[1] + t2[2]
   d1 = 60 * t1[1] + t1[2]
   diff = d2 - d1

   minutes = int(diff / 60)
   seconds = int(diff) % 60
   split ( diff, d, "." ) 
   printf "%1d:%02d.%d\n", minutes,  seconds,  d[2]
   exit 
}'

Hey,

Thanks for your reply. I know the script has some things in it which should be removed or changed, but I first would like to make it run fine. Once achieved, I will do a cleanup action. Thanks for the comments.

Also it was indeed not necessary to place the script within this post, but I thought it would be handy to help me out.

I think I can use your script very well, I`m going to test it right away!

Works great! Tx!

p.s. would you please remove the username/password from the quoted lines. I accidentally posted them as well :(.