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'