I'd like to have all the installed CPAN modules updated automatically every night, so I've placed the following command in the crontab:
#daily cpan -i $(cpanp -o | perl -lane 'print $F[3]')
However, whenever this is run I get the following error message:
Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work. The COLUMNS and
LINES environment variables didn't work. The resize program didn't work. at
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Term/ReadKey.pm
line 362.
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.8/Term/ReadLine
/Perl.pm line 63.
What can I do to get this working?
Come back on Monday. I'll add a -u command to cpan to do that if you promise to test it for me. You'll have to get the latest cpan from App::Cpan.
Okay, don't wait until Monday. I've pushed the change to the cpan-script Github repo, and App-Cpan 1.56_15 is on its way to CPAN.
Let me know if you have any problems or the new feature doesn't do what you want.
Please use brian d foy's answer as he added a cpan option to do this
Are you trying to update the list of modules with CPAN or actually update any out of date modules (d/l, compile, install)? This could be dangerous as modules could change interface and existing scripts would fail. This error is due to CPAN trying to use Term::ReadLine and Term::ReadKey to interrogate the terminal.
If you really want to upgrade all your modules, you can use this command:
perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
This is a small change from the command given in the documentation to interrogate CPAN for all outdated modules:
https://metacpan.org/pod/CPAN#PROGRAMMERS-INTERFACE
The COLUMNS and LINES environment variables didn't work.
Try setting the COLUMNS and LINES environment variables.
COLUMNS=80
LINES=24
#daily cpan -i $(cpanp -o | perl -lane 'print $F[3]')
Related
I am using the Dist::Zilla module to release and test my module. I am also using Perlbrew. When I run a script using perlbrew that includes my module, the script runs fine:
use strict;
use My::Module;
However, whenever I run dzil test, on a test that just tries to include my module:
#!perl -T
use strict;
use warnings FATAL => 'all';
use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'My::Module' ) || print "Bail out!\n";
}
diag( "Testing My::Module $My::Module::VERSION, Perl $], $^X" );
It fails with this error saying that it can't find the module Mouse (which my module includes):
Error: Can't locate Mouse.pm in #INC (you may need to install the Mouse module) (#INC contains:
/Users/user/github/My/Module/.build/HoKOnIQGYr/blib/lib
/Users/user/github/My/Module/.build/HoKOnIQGYr/blib/arch
/Users/user/perl5/lib/perl5/darwin-thread-multi-2level
/Users/user/perl5/lib/perl5/darwin-thread-multi-2level
/Users/user/perl5/lib/perl5
/opt/local/lib/perl5/vendor_perl/5.16.1/darwin-thread-multi-2level/
/Users/user/perl5/lib/perl5/darwin-thread-multi-2level
/Users/user/perl5/lib/perl5
/opt/local/lib/perl5/vendor_perl/5.16.1/darwin-thread-multi-2level/
/Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18
/Network/Library/Perl/5.18/darwin-thread-multi-2level
/Network/Library/Perl/5.18
/Library/Perl/Updates/5.18.2/darwin-thread-multi-2level
/Library/Perl/Updates/5.18.2
/System/Library/Perl/5.18/darwin-thread-multi-2level
/System/Library/Perl/5.18
/System/Library/Perl/Extras/5.18/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.18) at
/Users/user/github/My/Module/.build/HoKOnIQGYr/blib/lib/My/Module.pm line 4.
It says that it cannot find Mouse.pm, which I know is located at
/Users/user/perl5/lib/perl5/darwin-2level
I see that for some reason that directory is not located in #INC, which is interesting because if I run this command to print out all the directories in #INC:
perl -e 'print "$_\n" for #INC'
I get:
/Users/user/perl5/lib/perl5/darwin-2level
/Users/user/perl5/lib/perl5
/opt/local/lib/perl5/vendor_perl/5.16.1/darwin-thread-multi-2level/
/Users/user/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level
/Users/user/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0
/Users/user/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/darwin-2level
/Users/user/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0
.
So when I run perl on the command line then the darwin-2level directory is present in #INC, but whenever I run dzil test it is not. This might not have much to do with Dist::Zilla, since I think Dist::Zilla just creates Makefile.PL and runs make test for you. Could this be because for testing an older version of perl is being required? Like so:
use 5.006;
But even so, some Perlbrew directories are present in #INC during the test such as
/Users/user/perl5/lib/perl5/darwin-thread-multi-2level
Does anyone know how I can make it so I can use the Mouse installation in my perl directory instead of installing a systemwide one? I had a previous error with another module that couldn't be found when I ran dzil test, and that module was in the same directory as Mouse. I was able to fix the issue by installing the module systemwide instead of locally in my home perl5 directory, but I'd prefer to use the Mouse installed by Perlbrew and not mess with my system perl if possible. I am using Perlbrew version 0.73.
You're trying to install it using the wrong perl since you're using dzil installed by a different perl than the one you want to use.
Furthermore, you shouldn't see any of the following in your perlbrewed perl's #INC:
/Users/user/perl5/lib/perl5/darwin-2level
/Users/user/perl5/lib/perl5
/opt/local/lib/perl5/vendor_perl/5.16.1/darwin-thread-multi-2level/ (You perlbrewed perl isn't even threaded!!!)
Let's clean up your environment.
Unset env vars PERL5LIB, PERLLIB, PERL5OPT, PERL_MM_OPT and PERL_MB_OPT. Permanently. Get rid of them in your login scripts, then unset them from the current shell or log back in. (Make a note of what they were as a backup.)
Clear cpan's configuration item makepl_arg. From within cpan,
o conf makepl_arg # Just to see its current value as a backup.
o conf makepl_arg ''
o conf commit
In particular, we want to remove anything that indicates an installation path, including INSTALL_BASE, PREFIX and LIB.
Clear cpan's configuration item mbuildpl_arg. From within cpan,
o conf mbuildpl_arg # Just to see its current value as a backup.
o conf mbuildpl_arg ''
o conf commit
In particular, we want to remove anything that indicates an installation path, including --install_base, --prefix and --lib.
Since you're there, do the following from within cpan:
o conf build_dir_reuse 0
o conf commit
This will restore the setting to its default, which will save you headaches if it was changed.
Install the dependencies.
cpan Dist::Zilla Mouse
At this point, executing which dzil should give
/Users/user/perl5/perlbrew/perls/perl-5.16.0/bin/dzil
If so, you should be good to go.
If not, do hash -r and try which dzil again. (This shouldn't be needed, but just to be sure.)
If still not, provide the output of the following commands:
echo "$PATH"
which cpan
head -n 3 "$( which cpan )"
echo 'o conf' | cpan | grep arg
which dzil
head -n 3 "$( which dzil )"
perl -V # Uppercase "V"
I'd like to know if someone knows a function or command that I can put at the beginning of my Perl script that tells the user for example "this script is being run by perl v 5.XXX".
Specially when we have many versions installed.
$^V shows the "...revision, version, and subversion of the Perl interpreter." From perlvar.
You can use a special variable $]:
$ perl -e 'print $];'
5.014002
i am trying to use pp utility from PAR package to create an exe file of my Perl program on windows
eg
pp -o script.exe script.pl
The command runs ok, but when i try to run the exe, it gives me
The locale codeset (cp1252) isn't one that perl can decode, stopped at Encode/Locale.pm line 94. Compilation failed in require at LWP/UserAgent.pm line 1000.
What could be the problem? I have a list of modules being used in the script, these include, Cwd, LWP::Simple, LWP::Useragent , Win32::OLE.
enviroment:
1) windows vista
2) Activestate Perl 5.16
3) did not manage to install PAR::Packager successfully, unless i use "force" install, which manage to install.
thanks
Encode::Locale finds the modules it needs to decode various encodings in a way that pp can't discover automatically. You'll need to tell pp which additional modules are required.
This should do the trick:
pp -m Encode::Byte -o script.exe script.pl
I have a Perl Module that i created and i want to run one of the subroutine in it on a schedule. I know I can just make a small perl script that calls the subroutine and call it from the crontab but if there is a way to call the subroutine right from the crontab that would be cool!
Is this possible?
You can use Perl's -e switch for executing code from the command line, e.g.
perl -e 'use your_module; your_function()'
Make that even shorter with the -M switch for loading a module:
perl -Myour_module -e 'your_function()'
The perlrun man page is your friend.
You can run the subroutine from the command line using something like
perl -MYour::Module=some,functions,to,import,such,as,foo -e 'foo();'
So you will be able to do the same from the crontab. Note that the cron usually runs with a restricted set of environment variables, so you may need to add a -I/path/to/your/modules option.
If you want a more elegant solution, your module can be configured to detect that it is being run as a script and behave differently in that situation. See this discussion: In Perl, how can I find out if my file is being used as a module or run as a script?
I am fairly new to scripting with perl. I am trying to ssh into a server and perform some commands. I have to provide a username and password.
When trying to run the script that i have so far (code listed below). I get the following error.
I am assuming this means that i need to install/make Net/SSH/Perl.pm, however, when i follow the instructions and tutorials i have found online, none have worked.
Can someone please assist me. I have tried CPAN and ppm, CPAN says it cannot find net::ssh::perl or other variations of that string. And ppm will not even run, i do not see it in my perl directory. Any help is greatly appreciated!
// The code
#!/usr/bin/perl
use Net::SSH::Perl;
$uName = "username";
$pWord = "password";
$unitIp = $ARGV[0];
my $ssh = Net::SSH::Perl->new($unitIp, 35903);
$ssh->login($uName, $pWord);
my $out = $ssh->cmd("java -version");
print $out;
// the error that is returned
Can't locate Net/SSH/Perl.pm in #INC (#INC contains: /usr/lib/perl5/5.8.5/i386-linux-thread-multi /usr/lib/perl5/5.8.5 /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2 /usr/lib/perl5/site_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl/5.8.2 /usr/lib/perl5/vendor_perl/5.8.1 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl .) at needsAName.pl line 31.
BEGIN failed--compilation aborted at needsAName.pl line 31.
You can try this:
curl -L http://cpanmin.us | perl - --sudo App::cpanminus
cpanm Net::SSH::Perl
case sensitive.
Explanation:
1st line will install "cpanm" - what is IMHO the easiest way installing modules
2nd line will install the module Net::SSH::Perl
Instead of Net::SSH::Perl try using Net::SSH2 or if you are in an Unix/Linux environment Net::OpenSSH. They are far easier to install!
Why should you use Net::OpenSSH instead of other perl ssh? This is what I found after install it via cpanm:
Net::OpenSSH Vs Net::SSH::.* modules
Why should you use Net::OpenSSH instead of any of the other Perl SSH
clients available?
Well, this is the perldoc writters (biased) opinion:
Net::SSH::Perl is not well maintained nowadays (update: a new
maintainer has stepped in so this situation could change!!!), requires
a bunch of modules (some of them very difficult to install) to be
acceptably efficient and has an API that is limited in some ways.
Net::SSH2 is much better than Net::SSH::Perl, but not completely stable
yet. It can be very difficult to install on some specific operative
systems and its API is also limited, in the same way as Net::SSH::Perl.
Using Net::SSH::Expect, in general, is a bad idea. Handling interaction
with a shell via Expect in a generic way just can not be reliably done.
Net::SSH is just a wrapper around any SSH binary commands available on
the machine. It can be very slow as they establish a new SSH connection
for every operation performed.
In comparison, Net::OpenSSH is a pure perl module that doesn't have any
mandatory dependencies (obviously, besides requiring OpenSSH binaries).
just type cpan on terminal and then type: force install Net::SSH::Perl
perl -MCPAN -e 'install Net::SSH::Perl'