For one of my script, I want one extra parameter needs to be added to one of the Usage option. Below its given
#Check Input parameters are valid
if [ $# != 4 ]; then
function usage() {
echo
echo "*******************************************"
echo " !!! USAGE PARAMETERS !!! "
echo "*******************************************"
echo
echo
echo " " `basename $0`" <-l|-a> <DATE> <-c|-s> <SERVICE_NAME> "
echo
echo " <SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in 76S DIR.
<-L | -l> = Refining from LIVE LOGS.
<-A | -a> = Refining from Archive Logs , But date should be provided along with Option A , Date format yyyy-mm-dd
<-C | -c> = Client Specific Provider Error Code
<-S | -s> = Server Specific Provider Error Code
if [ $2 == $[aA] ]; then
function Archive() {
-a|-A) -a=$DATE $SERVICE_NAME
REQUIRED_OPT=2
*) usage
}
}
usage
fi
For Archive Log Option, mandatorily DATE option should be added in the format yyyy-mm-dd. Do this above option does work??
if the parameter is a little complex, you may want to take a look "getopts". it can handle many kinds of passed in parameters. e.g. cmd -A --timestamp yyyy-mm-dd
you can get more information by
man getopts
or
google getopts.
I tried with getopts , but still failing for some reason. Can someone assist for above query.
---------- Post updated at 12:42 AM ---------- Previous update was at 12:18 AM ----------
How to assign two arguments passed for option [aA] in the usage.
Is there anything that needs to be changed in the below snippet.
liveFilePattern="${HOME}/conf/app.properties.live.txt"
archFilePattern="${HOME}/conf/app.properties.archive.txt"
OPTRG=$1
SERVICE_NAME=$2
DATE=date +%y%m%d
ERROR_LOG_DIR=$HOME/ErrorLog/
OUT_FILE=$ERROR_LOG_DIR/$SERVICE_NAME_${DATE}
#The Log Path for the File Pattern
LOG_DIR="/logs/dev/app/logs/"
#The String Search File
#myString="${HOME}/conf/stringFile.txt"
#Check Input parameters are valid
if [ $# != 2 ]; then
function usage() {
echo
echo "*******************************************"
echo " !!! USAGE PARAMETERS !!! "
echo "*******************************************"
echo
echo
echo " " `basename $0`" [-l <SERVICE_NAME> | -a <YYYY-MM-DD> <SERVICE_NAME>] -c -s "
echo
echo " <SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in APP DIR.
<-L | -l> = Refining from LIVE LOGS.
<-A | -a> = Refining from Archive Logs , But date should be provided along with Option A , Date format yyyy-mm-dd
<-C | -c> = Client Specific Provider Error Code
<-S | -s> = Server Specific Provider Error Code
*) usage
}
usage
fi