Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like to write a bash script (that would be better if the script is in python) which executes a Perl script ( https://github.com/MangeshBiradar/Check_mk/blob/master/check_jenkins_jobs.pl) within it. It is the output that Perl script outputs:

CRITICAL ~ First_run ~ Build stability: 3 out of the last 4 builds failed. ~ 25
CRITICAL ~ Mangesh_Testing ~ Build stability: All recent builds failed. ~ 0
CRITICAL ~ MKS_Integrity ~ Build stability: All recent builds failed. ~ 0
OK ~ MKS_TEST ~ Build stability: No recent builds failed. ~ 100
CRITICAL ~ Rest_api_testing ~  ~ no score
CRITICAL ~ Second_job ~  ~ no score
OK ~ Team_test ~ Build stability: No recent builds failed. ~ 100
OK ~ test ~ Build stability: No recent builds failed. ~ 100
CRITICAL ~ TEST_1 ~ Build stability: 2 out of the last 3 builds failed. ~ 33
OK ~ Update_Outlook ~ Build stability: No recent builds failed. ~ 100

Now I have a task to be added into that bash/python script is to parse the Perl script output. According to the first field(CRITICAL, OK) in the parsed output I would like to return an appropriate value for CRITICAL return 2, for OK return 0 etc. What are some ways I can achieve this?

share|improve this question
    
What is the output of the Perl program? –  glenn jackman Jan 15 '13 at 15:05
    
Here is the output, when I double quoted the script to be executed in back ticks. its the output I was expecting. CRITICAL First_run Build stability: 3 out of the last 4 builds failed. 25 CRITICAL Mangesh_Testing Build stability: All recent builds failed. 0 CRITICAL MKS_Integrity Build stability: All recent builds failed. 0 OK MKS_TEST Build stability: No recent builds failed. 100 –  meMangesh Jan 16 '13 at 5:42
    
Add that information to the question so you'll be able to format it properly. –  glenn jackman Jan 16 '13 at 12:03
    
Updated the question with expected output. –  meMangesh Jan 16 '13 at 13:06
    
Is that the output of the Perl script that you now want to reformat? Or is that what you want to see and you have not shown what Perl outputs? I don't see any ~ characters there. –  glenn jackman Jan 16 '13 at 14:33
show 3 more comments

1 Answer

up vote 2 down vote accepted

Changing your for loop a bit:

for line in "${array[@]}"
do
   OIFS=$IFS                   # store old IFS in buffer
   IFS='~'                     # set IFS to '-'
   for i in $line
   do
      echo  $i
   done
  IFS=$OIFS
done
share|improve this answer
    
Thanks Guru!!It worked –  meMangesh Jan 15 '13 at 7:04
    
Hi Guru.. Updated the question. I am facing the same issue while I storing the Perl script output into an array and using that array for further work. –  meMangesh Jan 15 '13 at 7:40
    
Solved..!! Double quoted the Perl script to be executed in the back ticks. –  meMangesh Jan 15 '13 at 8:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.