Hi Monks!
I am removing the line with bgs in it. If it exists. Then,I am trying to add this line after the 'cron':
watch process procAlive 'bgs' 18 0x2 60 'Production Critical: bgs fail +ure. Restarting bgs' '/opt/EMPsysedge/bin/sysedge.sh'
Here is part of the file I'm trying to modify:
watch process procAlive 'cron' 1 0x2 60 'Production Critical: cro +n failure. Call USA POC' '/opt/EMPsysedge/bin/sysedge.sh' watch process procAlive 'inetd' 2 0x2 60 'Production Critical: in +etd failure. Call USA POC' '/opt/EMPsysedge/bin/sysedge.sh' watch process procAlive 'sendmail' 3 0x2 60 'Production Critical: sen +dmail failure. Call USA POC' '/opt/EMPsysedge/bin/sysedge.sh' watch process procAlive 'syslogd' 4 0x2 60 'Production Critical: sy +slogd failure. Call USA POC' '/opt/EMPsysedge/bin/sysedge.sh' watch process procAlive 'automountd' 5 0x2 60 'Production Critical: au +tomountd failure. Call USA POC' '/opt/EMPsysedge/bin/sysedge.sh' watch process procAlive 'xntpd' 6 0x2 60 'Production Critical: xn +tpd failure. Call USA POC' '/opt/EMPsysedge/bin/sysedge.sh' watch process procAlive 'itaagtd' 7 0x2 60 'Production Critical: it +aagtd failure. Call USA POC' '/opt/EMPsysedge/bin/sysedge.sh'
here are my errors: They have to do with my regex.
Use of uninitialized value at ./b.o-n line 16, <IN> chunk 86. Use of uninitialized value at ./b.o-n line 17, <IN> chunk 86. Use of uninitialized value at ./b.o-n line 16, <IN> chunk 87. Use of uninitialized value at ./b.o-n line 17, <IN> chunk 87. Use of uninitialized value at ./b.o-n line 16, <IN> chunk 88. Use of uninitialized value at ./b.o-n line 17, <IN> chunk 88. Use of uninitialized value at ./b.o-n line 16, <IN> chunk 89.
Here is my script.
Suggestions?
Thanks!
#!/usr/bin/perl -w use strict; my $cf_dir = "/fmac/sysadm/admin/sysedge/sys/sysedge/cf/"; my $CF = "watch process procAlive 'bgs' 18 0x2 60 'Production Critical +: bgs failure. Restarting bgs' '/opt/EMPsysedge/bin/sysedge.sh'"; open CF_FILES, "Servers.cf" or die "Can't Open Servers.cf file: $!"; #open CF_FILES, "Servers.test" or die "Can't Open Servers.test file: +$!"; my @cf_f=<CF_FILES>; #close CF_FILES; foreach my $cf(@cf_f) { chomp $cf; open IN, "$cf_dir/$cf" or die "Can't open '$cf' for input: $!\n"; #open OUT, ">$cf_dir/$cf.tmp" or warn "Can't write '$cf_dir/$cf.tmp': +$!\n"; open OUT, ">/tmp/$cf.tmp" or warn "Can't write '/tmp/$cf.tmp': $!\n"; my $file = do { local $/; <IN>}; s/^watch.*?'bgs'.*?sh'$//; s/^(watch.*?'cron'.*?sh'$)/$1\n$CF\n/; print OUT $file; } close OUT or die "Can't close filehandle OUT properly: $!\n"; chdir "/$cf_dir"; #rename "$cf.tmp", "$cf"; #}

In reply to regex problem? by wcj75019

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.