Link to home
Start Free TrialLog in
Avatar of Simon336697
Simon336697Flag for Australia

asked on

Multiple Parameters

Hi guys hope you can help.
Id like to be able to do build the following script that does the following..

checkfile.pl -b <business> -s <scope>  -n <remote file> -f <filename>
where:
<business>, <scope>, <remote file> and <filename> are parameters that are entered in by the user.

Options available would be:

<business>:      -b
"L" --- (for liquor),   # any systems in <filename> that start with the letter "l"
"S" --- (for store),   # any systems in <filename> that start with the letter "s"
"O" --- (for other)   # any systems in <filename> that start with the letter "o"

<scope>:           -s
"A" --- (for all systems in <filename> as defined by the -b switch eg. if user puts in "L" for the -b switch, and "A" for the s switch, then all ("A") liquor systems as defined in <filename> (as entered at the command line for the -f switch), would be processed),  
"S" --- (for systems ending in "NT001" in <filename>),
"N" --- (for systems that DONT end in "NT001" in <filename>)

<remote file>:      -n
a supplied full LOCAL path and file to the file you wish to check the existence for.

<filename>:        -f
a supplied name of a file that has a list of computers in it, 1 computer per line.
This file will be processed based on the criterion of the aforementioned switches, in order for filtering of machines in <filename>.

So, an example of user input to run the script would be:
checkfile.pl -b L -s A -n "d:\bin\testfile.txt" -f systems.txt

What the above would do is:
1) Read the systems.txt file (as defined by -f <filename>
2) Search for the business "L" - any systems that start with "L" (as defined by -b <business)
3) Grab ALL systems that start with "L" - all because of the -s A (as defined by -s <scope>)
4) Check for the existence of "d:\bin\testfile.txt" on the remote system (as defined by -n <remote file>)
5) If the file exists, write to a file called "fileexists.txt" with an entry for the computer name.
6) If the file doesnt exist, write to a file called "filenotexists.txt" with an entry for the computer name.
7) The user should be able to miss some of the parameters, thus being able to do the following:

checkfile.pl -n "d:\bin\testfile.txt" -f systems.txt

In which case, the script would read the systems.txt file, process every system in systems.txt, disregarding the -b and -s switches, and search for the existence of "d:\bin\testfile.txt" on the remote machine.

As the entry for the -n switch is inputted as local eg."d:\bin\testfile.txt", the d: has to be interpreted as a d\$
In other words, when a computer name is read from the <filename>, for example, LR2313NT001, when checking for the file existence, the path is \\\\$SystemName\\d\$\\bin\testfile.txt, if $SystemName is chosen as the variable name to set for the computers in <filename>.

I know how to do the code to connect to each machine, but the code for the multiple parameters is overwhelming, and any help appreciated.

This question will probably go over 2 questions, as I know there is a lot here.

Thanks guys.
Avatar of Adam314
Adam314

You can read parameters easily with the Getopt:Long module:
http://search.cpan.org/~jv/Getopt-Long-2.36/lib/Getopt/Long.pm


my ($Business, $Scope, $RemFileName, $FileName);
GetOptions ("b=s" => \$Business,
            "s=s" => \$Scope,
            "n=s" => \$RemFileName,
            "f=s" => \$FileName) or die "Invalid options\n";

die "Invalid -b option.  Valid options are L, S, and O.\n" unless $Business =~ /^(L|S|O)$/;
die "Invalid -s option.  Valid options are A, S, and N.\n" unless $Scope =~ /^(A|S|N)$/;
what is the format of the systems.txt file?
Avatar of Simon336697

ASKER

Hi Adam (hope you are going well!).

Mate the format is as follows for systems.txt

LN5834NT001
LS9286NW001
LW2722NW131
SA1209NT001
AS2390NT001
OS7399NQ001
LV6391NW231
OQ2322NT001
OV3187NT001
AN2333NT001
SW1259NT001
In the following systems.txt

LN5834NT001
LS9286NW001
LW2722NW131
SA1209NT001
AS2390NT001
OS7399NQ001
LV6391NW231
OQ2322NT001
OV3187NT001
AN2333NT001
SW1259NT001

------------------------------
The first character of each computer name is the business code.
So,
if its "L", its liquor,
if its "S", its store,
anything else is "O" for other.
Example:

checkfile.pl -b <business> -s <scope>  -n <remote file> -f <filename>

checkfile.pl -b S -s S -n "c:\test.txt" -f systems.txt

would work on finding systems starting with S, ending with NT001, testing for existence of c:\test.txt, computer system list from systems.txt

computers to process would be:

SA1209NT001
SW1259NT001

From the list mentioned in my last comment.

ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Adam mate thank you for this.

I havent had time to properly test this, but it looks great!
Let me know if there are any problems.