unix - salmanbaig8/imp GitHub Wiki

############################################## SCRIPT STARTS ################################################# ################### FUNCTIONALITY TO CHECK MULTIPLE PROCESSES ############################################### me=basename "$0" echo "Script Name--- $me ---------" pidCount=0

pid=$(ps -ef | grep "$me" | grep -v grep | awk '{ print $2 }')

for i in $pid do # echo "pid: $i" pidCount=expr $pidCount + 1 if $pidCount -gt 2 ; then echo -e "\n Exiting......Process $me is already running, Stop the Existing Process to Continue " exit fi

done

#########LOG FILE ################ fileName=$(echo $me | cut -f 1 -d '.') #echo $fileName currDir=$(pwd) #echo $currDir

LOGFILE=$currDir/logs/$fileNamedate +%m-%d-%y.log

#Function to LOG LOG() { MSG=$1 DATETIME=date "+%m-%d-%y:%H:%M:%S:" echo "${DATETIME}:${MSG}" >> ${LOGFILE} }

checkForDir(){ if ! -e $1 ; then mkdir $1 elif ! -d $1 ; then echo "$1 dir already exists but is not a directory" 1>&2 fi }

sendMailGeneric(){ subject=" $1 " body="Team " from=$from to=$TO_MAIL_IDS echo -e "Subject:${subject}\n${body}" | sendmail -f "${from}" -t "${to}" }

fileCheck() { if [ -f $1 ]; then rm $1 fi }

ConnectivityCheck(){ #### $1 is file name , $2 is count , $3 is API to be called ###### if ! -s $1 && $2 -gt $maxTries ; then echo "File $1 is empty, API: $3 call Failed" sendMailGeneric "API: $3 call Failed" "Please Check the Connectivity of the Server" exit 1 elif ! -s $1 ; then echo "Retrying ..." curl -X GET -k --header 'Accept: application/json' $3 >> $1 connCheckCount=expr $connCheckCount + 1 fi }

fileUpload(){ result=$(curl -X POST -k -i -H "Content-Type: multipart/form-data" -F "file=@$1" -F "model={"Id":0,"countryCode":"$2","userid":"$3","envId":"$4","description":"$5","zipName":"$6","ts":"null","code":"$7","statusId":"$8","pkgid":"$9"};type=application/json" $RESTUrl/$2/new) }

#Function for retry logic setting max number of retry retry(){ if $1 -gt $maxTries ; then echo -e "\n #############--- Exiting ---############# \n ......Clocked maximum number of retries.... \n ......Check Logs for the Issue....." sendMailGeneric "Execution Stopped in $countryCode:$env" "$1" exit else sleep $time fi }