Variable hold in UNIX job


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable hold in UNIX job
# 1  
Old 06-29-2017
Variable hold in UNIX job

In log directory file contain log files and files contain some unique job name which is dynamically created (example=55555 ),if job get 55555 then send alert message, but after next run if it find ---55555 then no need send alert message
While checking the first job name you are capturing the Job name, can we store this job name and while checking for next run 15 min interval if script will find same job name Then compare with old Job name to new job name if it is same then no need alert message to users
below mention files
Code:
 for i in $(find /path/of/target/directory -type f)
do if grep -i "the string to look for" "$i" > /dev/null
      then echo "$i" 
      job_name=
      mail -s "Alert" "abc@gmail.com"
fi
done

log files:

Code:
Sat Sep 26 12:05:41 2015 Internal trap notification jobname = 55555 (MMES1AssocFail) MME S1 Association failed;
Sat Sep 26 12:07:50 2015 Internal trap notification 1168 (MMES1AssocEstab) MME S1 Association established;
Sat Sep 26 12:07:50 2015 Internal trap notification 1190 (MMES1PathEstab) MME S1 path established;
Sat Sep 26 12:26:55 2015 Internal trap notification 1189 (MMES1PathFail) MME S1 path failed;
Sat Sep 26 12:26:55 2015 Internal trap notification 1167 (MMES1AssocFail) MME S1 Association failed;
Sat Sep 26 12:27:04 2015 Internal trap notification 1168 (MMES1AssocEstab) MME S1 Association established;
Sat Sep 26 12:27:04 2015 Internal trap notification 1190 (MMES1PathEstab) MME S1 path established;
Sat Sep 26 12:27:26 2015 Internal trap notification 1189 (MMES1PathFail) MME S1 path failed;
Sat Sep 26 12:27:26 2015 Internal trap notification 1167 (MMES1AssocFail) MME S1 Association failed;


Last edited by rbatte1; 06-29-2017 at 12:33 PM..
# 2  
Old 06-29-2017
I assume you want to run your script from crontab.
You can store the current job name in a file.
Before you do it, compare it with the old file contents; if different then send mail.
This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 06-30-2017
Am not using crontab its running by scheduling tools ,Could u please explain bit more or share me sample script so that i can analyzed
1.we can store that variable (job name into a file while second run it will check that temp file and compare the value if file size 0 then go to else part
# 4  
Old 07-03-2017
The following example maintaines ONE jobname in a file
Code:
jobfile=/tmp/jobsaved
read jobsaved < $jobfile
for f in $(find /path/of/target/directory -type f)
do
  # pull the jobname from the file
  sed '/.*jobname *= *\([0-9]\{1,\}\).*/!d; s//\1/; q' "$f"
  if [ -n "$jobname" -a "$jobname" != "$jobsaved" ]
  then
      echo "new $jobname in $f" # | mail -s "Alert" "abc@gmail.com"
      jobsaved=$jobname
      echo "$jobsaved" > $jobfile
  fi
done


Last edited by MadeInGermany; 07-03-2017 at 02:30 PM.. Reason: put a more efficient sed code
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to put the multiple job on-hold using shell script?

Hi.. I need to put multiple jobs on ON HOLD in Autosys.. please help me on this. For Example: 1)ABCD_EFGH_IJKL 2)abcd_efgh_ijkl (2 Replies)
Discussion started by: Maanjesh
2 Replies

2. Shell Programming and Scripting

What's the max integer a variable can hold?

I would like to know the maximum integer that a variable can hold. Actually one of my variable holds value 2231599773 and hence the script fails to process it.Do we have any other data type or options available to handle this long integers? (9 Replies)
Discussion started by: michaelrozar17
9 Replies

3. UNIX for Dummies Questions & Answers

built in variable to hold the name of therunning script...

Hi, I have multiple functions that can be called by any shell script. These functions have inbuilt echo statements to logs their activity into a log file. When I run multiple shell scripts that call these functions, they all log into the same log file and I am not able to differentiate which... (2 Replies)
Discussion started by: new_learner
2 Replies

4. UNIX for Dummies Questions & Answers

Introduction, and, needing my first foot hold on Unix

Just spent the last hour cruising the FAQ and doing some searches. I learn best by getting one or two books and just starting from scratch and building up a system. Looks like that's the way most of you recommend getting going anyway. I'm armed with several book titles now, and I'll head off to... (2 Replies)
Discussion started by: Rowan
2 Replies

5. Shell Programming and Scripting

killing unix job after the job process completes

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. ... (1 Reply)
Discussion started by: dtazv
1 Replies
Login or Register to Ask a Question