Author:
erics , November 9th, 2023
This was caused by having the PERL5LIB environment variable set.
root @ server1 : / root # /etc/webmin/restart-by-force-kill
Force stopping Webmin server in / usr / libexec / webmin
/ etc / webmin / . stop - init : line 10 : kill : ( 10111 ) - No such process
Starting Webmin server in / usr / libexec / webmin
/ usr / bin / perl : symbol lookup error : / root / perl5 / lib / perl5 / x86_64 - linux - thread - multi / auto / Net / SSLeay / SSLeay . so : undefined symbol : Perl_ss_handshake
root @ server1 : / root # unset PERL5LIB
root @ server1 : / root # /etc/webmin/restart-by-force-kill
Force stopping Webmin server in / usr / libexec / webmin
/ etc / webmin / . stop - init : line 10 : kill : ( 10111 ) - No such process
Starting Webmin server in / usr / libexec / webmin
Categories: How-To's , Technology Tags: env , environment , Error , howto , perl , Perl_xs_handshake , PERL5LIB , symbol lookup error , tips , undefined symbol , unset , Webmin
| No comments
Author:
erics , July 20th, 2021
my $ count = ( ) = $ string = ~ / \ n / g ;
Categories: How-To's , Technology Tags: Count , howto , Newline , perl , String , tips , Var , Variable
| No comments
Author:
erics , June 16th, 2021
my $ needle = 'foo' ;
my $ haystack = 'foo foo foo' ;
my @ count = $ haystack = ~ / $ needle / g ;
my $ count = scalar @ count ;
print "$count\n" ;
Should result in 3
Categories: How-To's , Technology Tags: Count , HayStack , howto , Needle , perl , Scalar , String , tips
| No comments
Author:
erics , April 16th, 2021
The key is to define a variable first, then use the BEGIN block to initialize the variable, then reference the variable in use lib $var; later on ;-} For example, enable a module contained in the same directory as a script called via the PATH:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/ussr/bin/env perl
use strict ;
use warnings ;
our $ scriptPath ;
BEGIN {
eval {
use File :: Basename ;
use File :: Spec ;
$ scriptPath = dirname ( File :: Spec -> rel2abs ( __FILE__ ) ) ;
1 ;
} or do {
die "$0 use CRASHED: $@" ;
} ;
}
use lib $ scriptPath ;
eval {
use MyModule :: ABC ;
1 ;
} or do {
die "$0 use CRASHED: $@" ;
} ;
Categories: How-To's , Technology Tags: @INC , compile , Compile-time , Dir , directory , howto , include , lib , Library , module , Path , perl , require , Run-time , runtime , tips , Use , use lib
| No comments
Author:
erics , March 9th, 2021
The trick to using eval to catch shell execution is to return twice, once inside the eval and once outside:
sub isMaintenance {
my $ return = eval {
my $ err = system ( "check_policy.sh | grep 'Policy is MAINTENANCE' >/dev/null 2>/dev/null" ) ;
& debug ( "perl error code: $err" ) ;
$ err = $ err / 256 ;
& debug ( "system error code: $err" ) ;
if ( $ err != 0 ) {
# Not Maintenance
if ( $ verbose ) { warn "policy is NOT MAINTENANCE\n" ; }
return 0 ;
} else { return 1 ; }
} ;
return $ return ;
}
Neat!
Categories: How-To's , Technology Tags: Code , eval , Exit , Exit Code , howto , perl , Return , System
| No comments
Author:
erics , February 11th, 2021
## to add a single backslash in front of whatever char was matched
my $ password = q #abc'A1r%Fgt&jh[-#;
$ password = ~ s / ( [ '])/\\$1/g;
print qq#' $ password '\n#;
' abc \ 'A1r % Fgt & jh [ - '
## to double whatever char was matched
my $ password = q #abc'A1r%Fgt&jh[-#;
$ password = ~ s / ( [ '])/$1$1/g;
print qq#' $ password '\n#;
' abc '' A1r % Fgt & jh [ - '
## to convert ‘ to ‘\” for shell execution
my $ password = q #abc'A1r%Fgt&jh[-#;
$ passwordShell = ~ s / ( [ '])/$1\\$1$1/g;
print qq#' $ password '\n#;
' abc '\'' A1r % Fgt & jh [ - '
Categories: How-To's , Technology Tags: Backslash , Characters , double , double quotes , Escape , howto , perl , quote , quotes , Replace , Single , single quotes , Speci , Special , Special character , Substitute , tips
| No comments
Author:
erics , December 3rd, 2020
Problem While running the aws cli command from a Perl async command inside apid, I go the following error:
IOError : [ Errno 10 ] No child processes
Solution The issue turned out to be a bug in Python2.7, so I upgraded to Python3.4, then uninstalled and re-installed the aws cli software so that it used the proper Python34 version. Procedure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sudo - i
cd
## Upgrade Python
yum install python34
alternatives -- config python
## "Uninstall" old aws cli
mv / opt / aws / opt / aws . fcs
cd / usr / bin /
mv aws aws . fcs
mv aws_completer aws_completer . fcs
## Install new aws cli
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" - o "awscliv2.zip"
unzip awscliv2 . zip
. / aws / install - i / opt / aws - b / usr / bin
/ usr / bin / aws -- version
https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html […]
Categories: How-To's , Technology Tags: alternatives , API , apid , AWS , aws cli , AWS Linux , Broken , cli , Cloudformation , Command , Curl , Error , Exec , Execute , howto , IOError , Linux , No child processes , perl , Python , Python27 , Python34 , tips , Yum
| No comments
Author:
erics , July 8th, 2020
my $ stamp = strftime "%Y%m%d%H%M%S" , gmtime time ;
## in-place update for the file
our $ ^ I = ".$stamp" ;
local @ ARGV = ( $ fullpath ) ;
while ( < ARGV > ) {
if ( / $ regex / ) {
next ;
}
# this print is the critical part to write the line back to the file
print ;
}
$ ^ I = undef ;
Categories: How-To's , Technology Tags: Change , Edit , Edit In Place , howto , in place , Inline , modify , perl , Place , Script , tips
| No comments
Author:
erics , July 8th, 2020
use POSIX qw ( strftime ) ;
my $ stamp = strftime "%Y%m%d%H%M%S" , localtime ;
my $ stamp = strftime "%Y%m%d%H%M%S" , gmtime ;
Categories: How-To's , Technology Tags: Date , datetime , gmtime , howto , localtime , perl , Stamp , strftime , time , timedate , Timestamp , tips
| No comments
Author:
erics , March 23rd, 2020
Using PERL, we can easily do a search and replace across multiple files. perl -ni -w -e ‘print unless m/^gdb\d+/;’ yourFileSpec
Categories: How-To's , Technology Tags: Batch , Delete , Edit , Edit In Place , howto , in place , perl , search , tips
| No comments