Skip to content
Advertisement

Shell script to automate the installation of cpan modules

I am writing a shell script to automate the installation of cpan (Comprehensive Perl Archive Network) modules.

#!/bin/bash
perl -MCPAN -e shell
o conf make_arg -I/"$PWD"
o conf make_install_arg -I/"$PWD"

The first command is being executed and it enters into the cpan shell, but the later commands are not detected. I think the later commands are not being executed as it is a different shell. Any leads on this is appreciated.

Thanks.

Advertisement

Answer

You are writing a bash script, and o conf .... is not a bash command.

You could remote control the CPAN shell, by either

  • providing all the input in a file, from where you redirect the stdin, i.e. perl -MCPAN -e shell <my_commands.txt. Note that this will fail, if the CPAN shell clears the input buffer after each command (I don’t think that it does, but it could be).

  • Write a expect script

  • Use your favorite programming language and use the Telnet protocol to steer the CPAN shell; since this is about Perl, you could use Perl’s Net::Telnet module.

  • Since the CPAN shell is written in Perl, I guess you can also write the whole thing completely in Perl, using the features which already there in the CPAN module. I would start by looking at the source code of the CPAN module to study, how the commands (for instance conf) are handled in Perl. After all, the CPAN shell is only one of the features of this module, although this is of course the one which people usually use.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement