Posted on 2007-07-24
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>
<business>, <scope>, <remote file> and <filename> are parameters that are entered in by the user.
Options available would be:
"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"
"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.
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.