-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #504 from cpanel/RE-743
Convert bash pipeline scripts to PERL.
- Loading branch information
Showing
7 changed files
with
116 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/local/cpanel/3rdparty/bin/perl | ||
|
||
use constant ELEVATE_LOG_PATH => '/var/log/elevate-cpanel.log'; | ||
|
||
use Env; | ||
|
||
use File::Tail; | ||
use POSIX; | ||
|
||
my $RETVAL = 1; | ||
my $RETRIES = 0; | ||
|
||
while ( $RETVAL != 0 ) { | ||
_check_elevate_log_for_regex( ELEVATE_LOG_PATH, ${REGEX}, $RETRIES ); | ||
} | ||
|
||
sub _check_elevate_log_for_regex { | ||
my ( $filepath, $REGEX, $RETRIES ) = @_; | ||
|
||
my $time = POSIX::strftime( "%Y-%m-%d %H:%M:%S", localtime ); | ||
|
||
$file = File::Tail->new( name => $filepath, maxinterval => 1, adjustafter => 7, interval => 1 ); | ||
while ( defined( $line = $file->read ) ) { | ||
if ( grep { /$REGEX/m } $line ) { | ||
print "## [$time] [INFO]: SUCCESS: Reboot regex ( $REGEX ) found in /var/log/elevate-cpanel.log ##\n"; | ||
exit 0; | ||
} | ||
$RETRIES++; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env perl | ||
|
||
use POSIX; | ||
|
||
my $HOST = $ARGV[0]; | ||
my $PORT = $ARGV[1] // 22; | ||
my $RETVAL = 1; | ||
my $RETRIES = 0; | ||
my $RETRY = $ARGV[2] // 60; | ||
|
||
return unless defined $HOST; | ||
|
||
while ( $RETVAL != 0 ) { | ||
my $cmd = qq{ /usr/bin/nc -z -w 3 $HOST $PORT }; | ||
my $output = `$cmd`; | ||
my $time = POSIX::strftime( "%Y-%m-%d %H:%M:%S", localtime ); | ||
|
||
$RETVAL = $?; | ||
|
||
if ( $RETVAL == 0 ) { | ||
print "## [$time] [INFO] SUCCESS: Connected to SSH on $HOST ##\n"; | ||
exit 0; | ||
} | ||
|
||
$RETRIES++; | ||
|
||
if ( $RETVAL != 0 ) { | ||
print "## [$time] [INFO]: Retrying SSH Connect: Attempt ${RETRIES} ...\n"; | ||
} | ||
|
||
if ( $RETRIES >= $RETRY ) { | ||
print "## [$time] [ERROR]: ssh_retry.pl: MAX_RETRIES has been reached.\n"; | ||
exit 1; | ||
} | ||
sleep 15; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env perl | ||
|
||
my $STAGE = $ARGV[0]; | ||
my $RELEASE_INFO = `cat /etc/redhat-release`; | ||
my $CPANEL_VERSION = `cat /usr/local/cpanel/version`; | ||
|
||
use strict; | ||
|
||
print "######################################\n"; | ||
|
||
sub main { | ||
my @arr = ( | ||
[ 'Stage:', $STAGE ], [ 'OS Release:', $RELEASE_INFO ] | ||
, [ 'cP Version:', $CPANEL_VERSION ] | ||
); | ||
|
||
for my $row (@arr) { | ||
format STDOUT = | ||
@<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<< | ||
@$row | ||
. | ||
write; | ||
} | ||
|
||
} | ||
|
||
main(); | ||
|
||
print "######################################\n"; |
This file was deleted.
Oops, something went wrong.