Computing.Net > Forums > Unix > Ksh script help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Ksh script help

Reply to Message Icon

Name: jonny5
Date: November 14, 2002 at 06:54:22 Pacific
OS: Solrais 8
CPU/Ram: E4500
Comment:

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>&1

echo "`date` : Started."

CHK_FILES= ( I wan to be able to have a date in here )
CHK_DIR=/jon/inbound/interfaces
FOUND=0

for file in ${CHK_FILES}
do
if [[ -f "${CHK_DIR}/${file}.hst" ]]
then
echo "Found interface file ${file}.hst"
FOUND=1
fi
done

if [[ $FOUND > 0 ]]
then
mailx -s "${PROGNAME}: Found Interface Files on ${HOSTNAME}" jon < ${LOGFILE}
else

mailx -s "${PROGNAME}: No Interface Files on ${HOSTNAME}" jon < ${LOGFILE}
fi

echo "`date`: Finished."




Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: November 14, 2002 at 10:21:55 Pacific
Reply:

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.


0

Response Number 2
Name: jonny5
Date: November 15, 2002 at 01:31:46 Pacific
Reply:

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.



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Ksh script help

Need Help With KSH Script www.computing.net/answers/unix/need-help-with-ksh-script/6747.html

KSH Script-Need Help www.computing.net/answers/unix/ksh-scriptneed-help/5534.html

Urgent help with KSH script www.computing.net/answers/unix/urgent-help-with-ksh-script/8014.html