0

This is a list of jobs in autosys. What I have to do is make sure that every job in PROD has a accompanying job in BACKUP. the jobs are formatted as CAPSER_JOB_01_PP. I read the list into a while loop, not sure if I should take an "-r" I take off the last two characters off of the job name, and then grep twice for each area, if both are successful it prints a yes at beginning of line, otherwise it is a no. Frankly I can't find matching documentation for the ${job%??}. I don't know what the two question marks stand for. I tried using grep -q but it did now work. the > 2>&1 /dev/null did not work, I had to reverse it to > /dev/null the the redirect 2>&1 (as shown) The script works, it is just a clunky way of getting it done. there has to be a better way.

#!/bin/bash
#bash, version 3.2.25

IFS=,

while read area job machine script
do
if grep  ${job%??} /home/first_spreadsheet.txt | grep BACKUP >/dev/null 2>&1 && grep  ${job%??} /home/first_spreadsheet.txt | grep PROD  >/dev/null 2>&1 ; then
echo " YES $area $job $machine $script "
else
echo " NO $area $job $machine $script "
fi
sleep 1
done < /home/first_spreadsheet.txt


cat /home/first_spreadsheet.txt
BACKUP, CAPSER_JOB_01_PP, usa-penguin.com, /bin/bash -lc '/usr/bin/run.sh'
PROD, CAPSER_PROD_JOB_01_PS, usa-penguin.com, /bin/bash -lc '/usr/bin/run.sh'
BACKUP, CAPSER_JOB_02_PP, usa-penguin.com, /bin/bash -lc '$HOME/run/script02'
PROD, CAPSER_PROD_JOB_02_PS, usa-penguin.com, /bin/bash -lc '$HOME/run/script02'
BACKUP, CAPSER_JOB_03_PP, usa-penguin.com, /bin/bash -lc '$HOME/run/script03'
PROD, CAPSER_PROD_JOB_03_PS, usa-penguin.com, /bin/bash -lc '$HOME/run/script03'
BACKUP, CAPSER_JOB_04_PP, usa-penguin.com, /bin/bash -lc '$HOME/run/script04'
PROD, CAPSER_PROD_JOB_04_PS, usa-penguin.com, /bin/bash -lc '$HOME/run/script04'
PROD, CAPSER_PROD_JOB_05_PS, usa-penguin.com, /bin/bash -lc '$HOME/run/script05'
PROD, CAPSER_PROD_JOB_06_PS, usa-penguin.com, /bin/bash -lc '$HOME/run/script06'
BACKUP, CAPSER_JOB_07_PP, usa-penguin.com, /bin/bash -lc '$HOME/run/script07'
PROD, CAPSER_PROD_JOB_07_PS, usa-penguin.com, /bin/bash -lc '$HOME/run/script07'
4
  • What's the question here? If it works and you're just trying to improve it, you could consider the code review stack exchange Commented Oct 26, 2017 at 20:30
  • id there a better way to figure out tht a job exists in two places besides a double grep ? Commented Oct 26, 2017 at 20:31
  • Why are you putting a GNU copyright notice in your script? Commented Oct 26, 2017 at 21:08
  • I'll go to code review. Commented Oct 26, 2017 at 21:36

1 Answer 1

1

You should avoid the loop. You can start with

sort -k3 /home/first_spreadsheet.txt | uniq -c

or with

grep PROD /home/first_spreadsheet.txt | 
   grep -vf <(sed -rn '/^BACKUP/ s/^[^,]*,[^,]*,//p' /home/first_spreadsheet.txt)

or with

awk -F, '{a[$3","$4]+=1}
         END {for (key in a)
                {print key ": " a[key] " time(s)"}
             }
        ' /home/first_spreadsheet.txt
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.