I'm trying to execute a shell script from one server(plantz1). While executing, I have written the script in such a way that it should log in to another system (globez1) and in that second system, one perl script should be running. But i'm getting errors like below:
Please help me somebody on this. Below, I'm taking the commands from the script and showing you the o/p.
plantz1:nyop% ssh globez1 "export PATH=/ilx/ops/sbin:$PATH; /ilx/ops/sbin/mklive_pour ewh drop"
Use of uninitialized value $ENV{"IR"} in concatenation (.) or string at /ilx/ops/sbin/mklive_pour line 25.
Use of uninitialized value $ENV{"IR"} in concatenation (.) or string at /ilx/ops/sbin/mklive_pour line 25.
Use of uninitialized value $ENV{"IR"} in concatenation (.) or string at /ilx/ops/sbin/mklive_pour line 69.
Use of uninitialized value $ENV{"IR"} in concatenation (.) or string at /ilx/ops/sbin/mklive_pour line 69.
No symon.def file? :No such file or directory at /ilx/ops/sbin/mklive_pour line 69.
plantz1 is first server
globez1 is secondary server
/ilx/ops/sbin/mklive_pour - it's the perl script
The %ENV hash contains the environment variables from the operating system environment that started your process. $ENV{IR} contains the value of the IR environment variable. The warning you are getting is telling you that this variable has not been set.
You need to set this variable before running your command. It looks like you're running Linux, so something like this will work:
plantz1:nyop% export IR=something
Unfortunately, as I don't know anything about the software you're trying to use, I can't give you any help as to what the value of that variable needs to be.
Related
I try to use Perl to global replace the email address in my shell scripts but it seems Perl can not replace if there is # character.
Part of my shell script:
MAIL_LIST_2="user01#abc.com"
The perl command:
perl -pi -e "s/user01#abc.com/user01#devemail.abc.com/g" test.sh
Any idea?
Escape the # sign in the email addresses in the Perl code:
echo 'MAIL_LIST_2="user01#abc.com"' |
perl -p -e "s/user01\#abc.com/user01\#devemail.abc.com/g"
which gives the output:
MAIL_LIST_2="user01#devemail.abc.com"
The problem is that Perl regards an unescaped # as the sigil for an array, and tries to interpolate the content of the (non-existent) arrays into the regex, which doesn't work as you want it to.
Note that if you enabled warnings — -w on the command line, or use strict; use warnings; in a script file — then you get told why things are not working so well:
echo 'MAIL_LIST_2="user01#abc.com"' |
perl -pwe "s/user01#abc.com/user01#devemail.abc.com/g"
Possible unintended interpolation of #abc in string at -e line 1.
Possible unintended interpolation of #devemail in string at -e line 1.
Name "main::abc" used only once: possible typo at -e line 1.
Name "main::devemail" used only once: possible typo at -e line 1.
MAIL_LIST_2="user01#abc.com"
Moral: always enable warnings in Perl scripts — it avoids unnecessary pain.
I just ran into this problem.
Possible unintended interpolation of #example in string at ./test/capture.pl line 20.
Possible unintended interpolation of #host in string at ./test/capture.pl line 20.
Global symbol "#example" requires explicit package name (did you forget to declare "my #example"?) at ./test/capture.pl line 20.
Global symbol "#host" requires explicit package name (did you forget to declare "my #host"?) at ./test/capture.pl line 20.
Solution is of course quoting, and I found the answer after a lot of googling.
$line5 is the one giving the line 20 error.
$line4 has the answer. The q() does single-quotes
my ($line4) =
q(Message 1A2D2V0L007336 from [20.85.223.71] <> to <user#example.com> with subject 'Postmaster notify: see transcript for details' message-id '<202111021302.1A2D2kq3001573#host.example.com>' date 'Tue, 2 Nov 2021 14:02:46 +0100' infected by {HEX}EICAR.TEST.3.UNOFFICIAL);
my ($line5) =
"Message 1A2D2V0L007336 from [20.85.223.71] <> to <user#example.com> with subject 'Postmaster notify: see transcript for details' message-id '<202111021302.1A2D2kq3001573#host.example.com>' date 'Tue, 2 Nov 2021 14:02:46 +0100' infected by {HEX}EICAR.TEST.3.UNOFFICIAL";
Reference: Strings in Perl: quoted, interpolated and escaped
How can I run this command in my Jenkins file?
sh "perl -p -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : $&/eg; s/\$\{([^}]+)\}//eg' .env"
I tried everything.
Like so:
sh """
perl -p -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : $&/eg; s/\$\{([^}]+)\}//eg' .env
"""
Or escaping the backslahes.
But I keep getting the error:
WorkflowScript: 13: unexpected char: '\' # line 13, column 23.
Depending on how this command is run, the string interpolation issues can be awful to predict. Is the double quoted string interpolated by sh? Does the backslash in front of $ mean that it is escaped from sh, but not from Perl interpolation? When I ran a test string in pastebin, it simply removed the $ENV{$1}.
I'm sure there's a way to do it the hard way (this way), but an easy way is to just write the Perl code in a file instead, and run the file.
I would write your regexes like this, in a separate file, say foo.pl:
s|\${([^}]+)}|$ENV{$1} // $&|eg;
s/\${([^}]+)}//g;
Using the logical defined-or operator // is slightly prettier than using the ternary operator. We change delimiter on the substitution operator to facilitate that.
I removed unused e modifier on second substitution.
You should note that all strings that match the regex ${....} will be removed from the input by the second substitution. So the fact that you attempt to put them back with the first substitution with $& is quite meaningless. Moreover using $& carries a notable performance reduction. Assuming that is a mistake from your side, the code can be shortened to:
s/\${([^}]+)}/$ENV{$1}/g;
Note that now you can also skip the dangerous eval modifier /e.
If you run it without warnings, which you do in your original code, you will not notice the undefined values in the %ENV hash, it will just return the empty string -- i.e. remove undefined values.
This code can now be run by your other script without interpolation issues:
sh "perl -p foo.pl .env"
Just remove the -e switch since you are no longer providing command line code.
I'm trying to install the Text::Template module with cpan but get this when I run 'install Text::Template' from the cpan shell.
cpan> install Text::Template
Reading 'C:\Perl64\cpan\sources\authors\01mailrc.txt.gz'
Use of uninitialized value $command in concatenation (.) or string at C:\Perl64\lib/CPAN/Tarzip.pm line 163, <IN> line 1.
'-qdt' is not recognized as an internal or external command,
operable program or batch file.
............................................................................DONE
Reading 'C:\Perl64\cpan\sources\modules\02packages.details.txt.gz'
Use of uninitialized value $command in concatenation (.) or string at C:\Perl64\lib/CPAN/Tarzip.pm line 163.
'-qdt' is not recognized as an internal or external command,
operable program or batch file.
Warning: Your C:\Perl64\cpan\sources\modules\02packages.details.txt.gz does not contain a Line-Count header.
Please check the validity of the index file by comparing it to more
than one CPAN mirror. I'll continue but problems seem likely to
happen.
Warning: Your C:\Perl64\cpan\sources\modules\02packages.details.txt.gz does not contain a Last-Updated header.
Please check the validity of the index file by comparing it to more
than one CPAN mirror. I'll continue but problems seem likely to
happen.
.Could not split line["┬0\cL²\cU\c?└'¸\cCé"]
Could not split line["cÌX'ÔÒ"├█\cP\cE?▀&Ù┌╠5Ó%â¥mþlýBô¶ñg▒R\cIØ\cT\cPȸ\cX."]
Could not split line["\cH·©s:░KÉþ\cC\c^Û{65j¼¸\cL"]
Could not split line["\cD│í¬ð\cP|:ü▒HôU▓┴Bú‗Ð\cZyÄ"]
Giving up parsing your C:\Perl64\cpan\sources\modules\02packages.details.txt.gz, too many errorsReading 'C:\Perl64\cpan\sources\authors\01mailrc.txt.gz'
Use of uninitialized value $command in concatenation (.) or string at C:\Perl64\lib/CPAN/Tarzip.pm line 163.
'-qdt' is not recognized as an internal or external command,
operable program or batch file.
............................................................................DONE
Reading 'C:\Perl64\cpan\sources\modules\02packages.details.txt.gz'
Use of uninitialized value $command in concatenation (.) or string at C:\Perl64\lib/CPAN/Tarzip.pm line 163.
'-qdt' is not recognized as an internal or external command,
operable program or batch file.
Warning: Your C:\Perl64\cpan\sources\modules\02packages.details.txt.gz does not contain a Line-Count header.
Please check the validity of the index file by comparing it to more
than one CPAN mirror. I'll continue but problems seem likely to
happen.
Warning: Your C:\Perl64\cpan\sources\modules\02packages.details.txt.gz does not contain a Last-Updated header.
Please check the validity of the index file by comparing it to more
than one CPAN mirror. I'll continue but problems seem likely to
happen.
.Could not split line["┬0\cL²\cU\c?└'¸\cCé"]
Could not split line["cÌX'ÔÒ"├█\cP\cE?▀&Ù┌╠5Ó%â¥mþlýBô¶ñg▒R\cIØ\cT\cPȸ\cX."]
Could not split line["\cH·©s:░KÉþ\cC\c^Û{65j¼¸\cL"]
Could not split line["\cD│í¬ð\cP|:ü▒HôU▓┴Bú‗Ð\cZyÄ"]
Giving up parsing your C:\Perl64\cpan\sources\modules\02packages.details.txt.gz, too many errorsLockfile removed.
I'm using ActivePerl 5.28.1 64bit on Windows 10. The same problem occurs for all the packages I tried, including Log::Log4perl and Test::More.
I can replicate this by corrupting my sources/modules/02packages.details.txt.gz file.
Erase the files in the C:\Perl64\cpan\sources\modules directory and try again.
I got it to work using Strawberry Perl instead of ActivePerl.
Has anyone tried this code on cygwin?
I get these errors:
Can't find string terminator "'" anywhere before EOF at -e line 1.
Use of uninitialized value in pattern match (m//) at ./dos_it.pl line 506.
Use of uninitialized value $shellpath in rindex at ./dos_it.pl line 586.
Use of uninitialized value $shellpath in substr at ./dos_it.pl line 586.
Use of uninitialized value $pathToShell in concatenation (.) or string at ./dos_it.pl line 761.
Use of uninitialized value $shell_conformance in concatenation (.) or string at ./dos_it.pl line 761.
The string that is generated is:
$ ps -ef | perl -ane '1..1 and /^(.*)CO?MM?A?N?D/ and $s=length $1;s/^.{$s}//; print "#F[1,2] $_"'
Perl version:
$ perl -v
This is perl 5, version 26, subversion 2 (v5.26.2) built for MSWin32-x64-multi-thread
That is a command for the Bourne shell (sh) or similar, but you gave it to the Windows shell (cmd) to execute. Execute the command using sh or similar (whether cygwin-built or otherwise) to get rid of the error.
By the way, you were using a Windows build of Perl (MSWin32-x64 arch), not a cygwin build of Perl (cygwin arch). That's not the cause of the error, as the program will run fine either way. That said, this "issue" will surely go away once you use a cygwin-built sh or similar to execute the command.
I am pretty layman to Perl, never used it ...but now I want to use it.
Here is what I did:
http://www.activestate.com/activeperl/downloads
I installed universal version - 5.12.4.1205
To test my program is working, I used the following small program :
dnacon.plx
#i/Perl64/bin/perl -w
#Example 1-1 Concatenating DNA
$DNA1 = 'ATTTGGTAAAATGTATA'
$DNA2 = 'TTTTGGGTTTGAAAT'
print "Here are two DNA fragments: \n\n"
print $DNA1, "\n\n"
print $DNA2, "\n\n"
$DNA3 = "$DNA1$$DNA2"
print "$DNA3\n\n
When I try to execute it the following is command prompt with errors.
Sorry for too basic question...
EDTIS:
When I just type dnacon.plx, it is seems that it is working, but with error !!!
c:\myperllessions>dnacon.plx
Scalar found where operator expected at C:\myperllessions\dnacon.plx line 5, nea
r "$DNA2"
(Missing semicolon on previous line?)
syntax error at C:\myperllessions\dnacon.plx line 5, near "$DNA2 "
Execution of C:\myperllessions\dnacon.plx aborted due to compilation errors.
Am I good to go ??? What could be the error ...compilation errors ????
Edits:
I am using the following now : is this correct ?
#i/Perl64/bin -w
Edits:
I changed my script to following:
#i/Perl64/bin -w
#Example 1-1 Concatenating DNA
use strict;
use warnings;
$DNA1 = 'ATTTGGTAAAATGTATA';
$DNA2 = 'TTTTGGGTTTGAAAT';
print "Here are two DNA fragments: \n\n";
print $DNA1, "\n\n";
print $DNA2, "\n\n";
$DNA3 = "$DNA1$$DNA2";
print "$DNA3\n\n";
I got the following error:
c:\myperllessions>dnacon.plx
Global symbol "$DNA1" requires explicit package name at C:\myperllessions\dnacon
.plx line 5.
Global symbol "$DNA2" requires explicit package name at C:\myperllessions\dnacon
.plx line 6.
Global symbol "$DNA1" requires explicit package name at C:\myperllessions\dnacon
.plx line 9.
Global symbol "$DNA2" requires explicit package name at C:\myperllessions\dnacon
.plx line 10.
Global symbol "$DNA3" requires explicit package name at C:\myperllessions\dnacon
.plx line 12.
Global symbol "$DNA1" requires explicit package name at C:\myperllessions\dnacon
.plx line 12.
Global symbol "$DNA2" requires explicit package name at C:\myperllessions\dnacon
.plx line 12.
Global symbol "$DNA3" requires explicit package name at C:\myperllessions\dnacon
.plx line 13.
Execution of C:\myperllessions\dnacon.plx aborted due to compilation errors.
Is my problem now with programming knowledge or something to do with installation ?????
To get perl to be recognized, you must add C:\Perl64\bin to the PATH environment variable. Go to Control Panel > System > Advanced System Settings > Environment Variables. Edit the line containing PATH in the top box marked User variables for <user>, and add ;C:\Perl64\bin (note the semicolon) to the end. Be sure not to corrupt anything that's already there.
The problems you are left with in your latest edit - Global symbol requires explicit package name - are because you have added use strict (a very good thing to do) and you haven't declared your variables. Also the line #i/Perl64/bin -w won't do anything and may as well be removed. Write this instead
use strict;
use warnings;
my $DNA1 = 'ATTTGGTAAAATGTATA';
my $DNA2 = 'TTTTGGGTTTGAAAT';
print "Here are two DNA fragments: \n\n";
print $DNA1, "\n\n";
print $DNA2, "\n\n";
my $DNA3 = "$DNA1$$DNA2";
print "$DNA3\n\n";
Did you try out Strawberry perl? It takes care of setting up the environment vars for you.
An environment variable may not be set up yet.
Since I no longer use Windows, I cannot give you the exact step by step instructions, but I can tell you, that somewhere in System Properties, you'll find a place to edit the environment variables.
Edit the path variable and append 'C:\Perl64\bin\' to it.
P.S.:This is assuming that when you cd to the said path, you are able to run the perl program. If not, something is wrong with the installation. Try re-installing Perl.