Search code examples
perlunattended-processing

Can I write a program to gather parameters in order to generate script to guide a binary file installation


OK, just as concept:

The base platform is Suse Enterprise server 11.1

I have a binary file to install; to install it, I need input some value such as ip address, cert location and so on.

Now what I want to do is to write a perl program to gather all input information first and then generate a script to guide the binary file install unattended.

Can it be done? I'm a fresh Perl learner.

Thanks.


Solution

  • The easiest way to get paramters via Console, is to use the Getopt Module. You can find further informations about that here:

    For example:

    use Getopt::Long;
    my $data = "bin_file";
    my $length = 24;
    my $verbose;
    GetOptions ("length=i" => \$length, # numeric
    "file=s" => \$data, # string
    "verbose" => \$verbose
    ) # flag
    or die("Error in command line arguments\n");
    

    Then you can call your script (inside your shell) with:

    $ perl script.pl --length 14 --file test.dat --verbose
    

    Getopt parses the command line from @ARGV , recognizing and removing specified options and their possible values.