Hello All, I have a script that is suppose to check aws api for cloudformation stacks that are out of sync and then send an email. The script works for the most part but it seems to work irrationally when doing a search for the word SYNC.Below is put output that shows all of the stacks are in sync pulled from the aws api, but at times the script reads some as IN_SYNC and other times goes to the else section of the script which will send an email if there is a script found to be out of sync. An example of the output is below (the top shows the the script is in sync and should output Setup ok, but some even though it shows insync says it is when it is not)
IN_SYNC Stack AviatrixGatewaySetup is OK!! IN_SYNC Stack ChildEC2 is out of sync!! SEND EMAIL NOW!! IN_SYNC IN_SYNC Stack ChildEFS is OK!! IN_SYNC IN_SYNC Stack ChildElasticache is OK!! IN_SYNC IN_SYNC Stack ChildFargate is OK!! IN_SYNC Stack ChildRDS is OK!! IN_SYNC IN_SYNC Stack ChildSQs is OK!! IN_SYNC Stack ChildSns is OK!! IN_SYNC Stack EFDEVProject is out of sync!! SEND EMAIL NOW!! IN_SYNC Stack S3 is out of sync!! SEND EMAIL NOW!! IN_SYNC Stack Users is OK!! IN_SYNC IN_SYNC Stack VPC2 is OK!! IN_SYNC IN_SYNC Stack parent is OK!! IN_SYNC Stack test-sample-function is OK!!
My code
#!/usr/bin/perl use strict; use warnings; my $ID; my @FINAL; my $SYNC; my $stack; my $DETECTION; #my $email=''; my @STACK_NAME=qx(aws cloudformation list-stacks --stack-status-filter + CREATE_COMPLETE UPDATE_COMPLETE --query 'sort_by(StackSummaries, &S +tackName)[*].[StackName]' --output text ); for $stack (@STACK_NAME) { chomp($stack); $ID=qx(aws cloudformation detect-stack-drift --stack-name "$stack" | j +q .[] | awk -F '\"' '{print \$2}'); chomp($ID); ##Get status based on ID do { $SYNC=qx(aws cloudformation describe-stack-drift-detection-status +--stack-drift-detection-id $ID | grep StackDriftStatus | awk -F '\"' +'{print \$4}'); $DETECTION=qx(aws cloudformation describe-stack-drift-detection-st +atus --stack-drift-detection-id $ID | grep DetectionStatus | awk -F ' +\"' '{print \$4}'); #system qq{aws cloudformation describe-stack-drift-detection-statu +s --stack-drift-detection-id $ID | grep DetectionStatus | awk -F '"' +'{print \$4}'}; system qq{aws cloudformation describe-stack-drift-detection-status + --stack-drift-detection-id $ID | grep StackDriftStatus | awk -F '\"' + '{print \$4}'}; chomp($DETECTION); chomp($SYNC); } until(("$DETECTION" eq 'DETECTION_COMPLETE') || ("$DETECTION" =~ + /DETECTION_FAILED/mi)) ; #if($SYNC eq 'IN_SYNC') if ( 'IN_SYNC' =~ /$SYNC/mi ) { print "Stack $stack is OK!!\n"; } else { print "Stack $stack is out of sync!! SEND EMAIL NOW!!\n\n"; #system qq{aws ses send-email --from "systems\@eemail.com" --d +estination "ToAddresses=$email" --message "Subject={Data=Cloudformati +on Drift Detected,Charset=utf8},Body={Text={Data=String,Charset=utf8} +,Html={Data=A Cloudformation stack has been detected to be out of SYN +C on Stack $stack,Charset=utf8}}" --region us-east-1}; } }
Any help would be appreciated thank you

In reply to word search in perl script by cbtshare

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.