Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Below is a korn shell script which i would like under the CHK_FILES line to be able to look for files which have a date format eg 14112002 (which change daily) i would then like to pass these files down the script so i end up with 141102.hst file.
Any help would be good.#!/usr/bin/ksh
#
# Program : chk_interface_hstfiles
#
# Date : 13th November, 2002
#
# Author : Jon
#
# Description : This script checks for the existance of date specifix hst files
# and emails a notification to mail_acount.
#
#
###################################################################################### Initialise global variables
PROGNAME=${0##*/}
HOSTNAME=`hostname`
CTL_DIR=/usr/local/etc
LOG_DIR=/usr/local/logs
BIN_DIR=/usr/local/bin
LOGFILE=${LOG_DIR}/${PROGNAME}.log
exec > ${LOGFILE} 2>&1echo "`date` : Started."
CHK_FILES= ( I wan to be able to have a date in here )
CHK_DIR=/jon/inbound/interfaces
FOUND=0for file in ${CHK_FILES}
do
if [[ -f "${CHK_DIR}/${file}.hst" ]]
then
echo "Found interface file ${file}.hst"
FOUND=1
fi
doneif [[ $FOUND > 0 ]]
then
mailx -s "${PROGNAME}: Found Interface Files on ${HOSTNAME}" jon < ${LOGFILE}
elsemailx -s "${PROGNAME}: No Interface Files on ${HOSTNAME}" jon < ${LOGFILE}
fiecho "`date`: Finished."

Not clear on exactly what you are asking for?
For the CHK_FILES= line, are you asking how to set CHK_FILES to the current date in your desired format?
That would be:
CHK_FILES=`date +%d%m%Y`
Be sure to use backquotes, not normal single quotes.
With capital Y you get the 4 digit year. WHen you want the 2 digit year, use small y.
run "man date" to see all the options.

Thankyou for the follow up , this script is run daily to chek for exsitence of .hst files , so when the script runs i need the script to check for matching date in the CHK_FILES= this output needs to be passed to if [[ -f "${CHK_DIR}/${date}.hst" ]] where date is output from CHK_FILES.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |