I need a script to automate something that has become a very tedious and risk-prone procedure that I have to perform several times a day. Worse, I am going to have to teach someone else how to do it with a “Zero” margin of error. I am hoping someone here can offer some ideas on how to accomplish the following:
The script should ask me to input two variables to be used to perform a series of tasks that never varies
The first step would input a name (example "jimmyk") for the first variable $na1
The second would input a description (example: "jimmywins") for variable $nb2
(I need to use some variable name that is not likely to already exist in other scripts in case I have to join this script to interact with another script that could already be using them)
Then first procedure would be to check for any errors that would make these variables unusable. The naming conventions require that neither of these can have any capital letters, spaces, hyphens or other special characters (%, $, #, etc.) and a maximum length of 13 characters.
Next I have to check the existing databases in “c:\mainfolder\databases” to be sure there is not already a database using the name of the 2nd variable.
Finally, I need to check to see if there is preexisting subfolder of the first variable containing a folder by the name of the 2nd variable.
(example: There might be a folder C:\mainfolder\jimmyk\ but it cannot already contain the subfolder "jimmykwins".
If any of these is conditions exist ( if the "jimmykwins" subfolder already exists in C:\mainfolder\jimmyk" or if the "jimmykwins" database exists in "c:\mainfolder\databases" or if I accidentally made the name too long or included any capital letters or spaces etc.. as mentioned above this would result in an error message and send me back to the start to change the entered data to fix the problem.
If both inputs pass all these tests I need to use those input variables to create a subdirectory named "jimmyk" within a directory "C:\mainfolder" IF it does not already exist there.
(Example c:\mainfolder\jimmyk"). If it DOES already exist then proceed to the next step.
In the next step it should create a sub-subdirectory using the name of the second variable inside the directory of the first variable.
(example: "c:\mainfolder\jimmyk\jimmywins”)
There are or will be other sub-subdirectories such as "jimmyloses" or "jimmyties" but never another with the exact same name. If there is a preexisting subfolder with the name in variable $nb2 I would not want to overwrite it. This same rule applies to the creation of the new database file later. If any of these occur, that should be an automatic stop with an error flag.
The next step is to copy the contents of the “c:\mainfolder\master template” directory including all the files and folders contained into the newly created sub-directory
(This populates the directory “c:\mainfolder\jimmyk\jimmywins\" with all the files and folders from the master template. Currently done using xcopy or cut and paste if I am in GUI mode.)
Next, create an empty “MySQL” database of the correct type with the name "jimmywins" in the MySQL database folder.
(I currently use phpmyadmin to do this). If there already exists a database by that name, I would definitely not want to overwrite it or replace it in any way. This should have been caught back at the beginning and forced me to use some other name.
*Note: If the automatic database creation is a "deal-breaker" it is not an absolute necessity for the script. I can perform that part after all the rest is done*.*
Next step is to edit a file called "identityfile.cfg" which was copied from the "master template" into the "c:/mainfolder/jimmyk/jimmywins" directory. I need to replace the single instance of the word "masterdb" with the 2nd variable "jimmywins" for use in identifying the correct database for the main program to use later
(This is now done by editing the name-field in the identityfile.cfg file with Notepad++)
Finally, the last thing is to create a hyperlink used to access that database with the format "
http://www.mainfolder.com/1st variable/2nd variable" and writing it to an existing text file "info.txt" that was copied into the newly created subdirectory "c:\mailnfolder\jimmyk\jimmywins" when all the other files were populated there.
(Also now done with notepad ++)
I could be missing something but I think this is the procedural order I have been manually following to accomplish all the tasks done with those two variables
Currently the time needed to do all this is at least 15 minutes even for me and I have done it hundreds of times. The chances of a typo is high enough with me but would be higher with someone else who had never done it. A script to ensure that this procedure was followed properly at every step would be a godsend for sure
I hope everyone at
DC had a Merry Christmas and a Happy New Year. Like most I.T. people, I was working through the Holidays but still had time to remember how it used to be.
I think it is time for Santa to make another Donation to DC (In the General fund I guess) as so many of you have helped me with problems in the past I don't want anyone to feel missed or any less appreciated. I am not sure what happens to donations to the General fund but I assume they in some way benefit everyone.
Final Note: I already tried doing this with a program that "follows the mouse" to repeat all my steps pausing for me to enter the needed names at each place but it ended up taking just as long to do because I have to keep entering those variables over and over again. That is where it is possible to make a typo that screws up everything. I admit that I am not that good with this but "Ghost Mouse" or anything like it is definitely not an answer.