LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-15-2014, 11:29 PM   #1
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Rep: Reputation: Disabled
Is this code logic correct?


Hi,
I have a job schedular file(job runs on that particular time):
cat set_schd.cfg
#JOB SCHEDULES
BLLBD101 05:30
BLLBD102 06:40
BLLBD103 06:45
DWLBD104 07:15
BLLBD105 08:10
DWLBD106 08:30
DWLBD107 08:35
DWLBD108 09:15
DWLBD109 09:30
DWLBD110 09:35

BLLBD201 13:15
DWLBD202 13:25
DWLBD203 13:30
DWLBD204 14:20
DWLBD205 14:40
DWLBD206 14:45
BLLBD301 17:45
DWLBD302 18:00
DWLBD303 18:05
DWLBD304 18:40
DWLBD305 19:00
DWLBD306 18:30
DWLBD307 19:05

BLLBD401 22:15
DWLBD402 23:00
DWLBD403 23:15
DWLBD404 23:55
DWLBD405 05:30
DWLBD406 06:00

as per above schedule we will receive messages of jobs with good run or bad run

sometime job will start late and accordingly will get messages, considering this i have prepared a code, can some one please verify if the code satisfies all the conditions? could someone please advise if needs any modifications to the script?

Code:
#JOB LIST
#---------------------------------------------------------------#
JBLIST_FULL[0]="BLLBD101"
JBLIST_FULL[1]="BLLBD102"
JBLIST_FULL[2]="BLLBD103"
JBLIST_FULL[3]="DWLBD104"
JBLIST_FULL[4]="BLLBD105"
JBLIST_FULL[5]="DWLBD106"
JBLIST_FULL[6]="DWLBD107"
JBLIST_FULL[7]="DWLBD108"
JBLIST_FULL[8]="DWLBD109"
JBLIST_FULL[9]="DWLBD110"

JBLIST_FULL[10]="BLLBD201"
JBLIST_FULL[11]="DWLBD202"
JBLIST_FULL[12]="DWLBD203"
JBLIST_FULL[13]="DWLBD204"
JBLIST_FULL[14]="DWLBD205"
JBLIST_FULL[15]="DWLBD206"
JBLIST_FULL[16]="BLLBD301"
JBLIST_FULL[17]="DWLBD302"
JBLIST_FULL[18]="DWLBD303"
JBLIST_FULL[19]="DWLBD304"
JBLIST_FULL[20]="DWLBD305"
JBLIST_FULL[21]="DWLBD306"
JBLIST_FULL[22]="DWLBD307"

JBLIST_FULL[23]="BLLBD401"
JBLIST_FULL[24]="DWLBD402"
JBLIST_FULL[25]="DWLBD403"
JBLIST_FULL[26]="DWLBD404"
JBLIST_FULL[27]="DWLBD405"
JBLIST_FULL[28]="DWLBD406"

#---------------------------------------------------------------#

for JOB in "${JBLIST_FULL[@]}"
do
jb_rtv_date1=$(grep -A3 "$JOB" "$RTVIEW" | tail -1 | tr '[<>]' ' '| awk  '{print $5}')
jb_rtv_time1=$(grep -A3 "$JOB" "$RTVIEW" | tail -1 | tr '[<>]' ' '| awk  '{print $6}')
jb_rtv_status=$(grep -A3 "$JOB" "$RTVIEW" | tail -1 | tr '[<>]' ' '|awk -F ' ' '{ print $2,$3 }')
jb_rtv_day=$(grep -A3 "$JOB" "$RTVIEW" | tail -1 | tr '[<>]' ' '| awk  '{print $4}')
jb_rtv_hour=$(grep -A3 "$JOB" "$RTVIEW" | tail -1 | tr '[<>]' ' '| awk  '{print $6}'|cut -c1-2)
jb_rtv_min=$(grep -A3 "$JOB" "$RTVIEW" | tail -1 | tr '[<>]' ' '| awk  '{print $6}'|cut -c4-5)

# get specific info from set_schd.cfg
mtchTime=$( grep "$JOB" ${scriptDir}/${set_schd.cfg} | grep "${currTime}" )

         # do checks and generate output accordingly
if [[ "${sys_curr_day}" != "Sat" ]] && [[ "${sys_curr_day}" != "Sun" ]]
then

        if [[ "${currDate1}" == "${jb_rtv_date1}" ]]
        then
                if [[ -n "${mtchTime}" ]]
                then
                        echo "  ${currTime} is available in configuration file"
			
			jb_exists=$(grep -A3 "$JOB" "$RTVIEW")
			if [[ -n "${jb_exists}" ]]
			then
				echo "$JOB" Entry exists...!!!	

                        	if [[ "${currTime}" == "${jb_rtv_time1}" && "${jb_rtv_status}" == "GOOD RUN" ]]
                        	then
                               		 echo " entry found in RTView: GREEN...!!!"
                                	 set_color "$JOB" "$COLOR_GREEN"


                        	elif [[ "${currTime}" == "${jb_rtv_time1}"  && "${jb_rtv_status}}" == "BAD RUN" ]]
                        	then
                                echo " entry found in RTView: RED...!!!"
                                set_color "$JOB" "$COLOR_RED"
				fi

                        elif [[ -z "${jb_exists}" ]]
			then
				echo "$JOB" entry doesn't exist...!!!

				echo " entry not found in RTView: RED...!!!"
                                set_color "$JOB" "$COLOR_RED"
			fi
                elif [[ -z "${mtchTime}" ]]
                then
                        echo "  ${currTime} is not available in configuration file"

                        if [[ "${currTime}" == "${jb_rtv_time1}" && "${jb_rtv_status}" == "GOOD RUN" ]]
                        then
                                echo " entry found in RTView: GREEN...!!!"
                                set_color "$JOB" "$COLOR_GREEN"
			elif [[ "${currTime}" == "${jb_rtv_time1}"  && "${jb_rtv_status}" == "BAD RUN" ]]
                        then
                                echo " entry found in RTView: RED...!!!"
                                set_color "$JOB" "$COLOR_RED"
                        fi
                fi
        elif [[ "${currDate1}" != "{jb_rtv_date1}" ]]
	then
		echo "Entry is older..!!"
		set_color "$JOB" "$COLOR_GRAY"
	fi	
		
fi

done

Last edited by santosh0782; 02-16-2014 at 12:02 AM.
 
Old 02-16-2014, 01:44 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,841

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
would be much better to check it yourself. Does this script work as it was expected or is there any known problem with it?

I have only one comment, but it will not influence the program flow:
those grep|tail|tr|awk|cut chains causes a huge overload because executed 6 times inside a for loop (that means about 700 forked processes, a lot of pipes .... ) - and they can be replaced with a simple awk.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c code for transferring the data in MySQL using en-queue logic batman4 Programming 11 07-21-2012 02:44 PM
c code for transferring the data in MySQL using en-queue logic batman4 Programming 1 07-19-2012 07:11 PM
Add logic in the existing code dnaqvi Programming 1 03-02-2011 11:16 AM
LSI Logic / Symbios Logic 53c875 (rev 14) -> HP Storageworks 1/8 G2 gileravxr Linux - Hardware 0 07-21-2009 04:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration