r/ScriptSwap • u/loganbest • Jan 10 '13
[request] htaccess maintenance script
I'm wanting to write a script that will loop through each of my web roots, check for a .htaccess file AND a .htaccess_maintenance file.
- This script will have a stdin variable of either "on" or "off".
- If "on" it will find the production .htaccess rename it to .htaccess_live then rename .htaccess_maintenance to .htaccess.
- If for some reason .htaccess_maintenance doesn't exist it'll create it then rename it to .htaccess
If for some reason the site doesn't have a live .htaccess file, it will only rename .htaccess_maintenance to .htaccess.
This will all reverse if stdin is "off"
Here's the caveat, I'm a noob at shell and perl scripting. I can read it and understand it 100%, but I just don't know enough to write from scratch. I would much rather write this script myself in either language than have someone write it for me.
My ultimate question is, how can you help me write this with specific examples or resources?
View all comments
Show parent comment
1
u/rodmacpherson Bash CMD Python PowerShell Jan 10 '13
For every programming language there are some common building blocks. if, case, for, while, the ability to parse args, the ability to take an input...
If you can figure out the basic structure of what you want to accomplish in terms of these building blocks, Google will help you figure out the syntax for writing it in bash, or perl, or java, or python, or whatever you need to use.
I find that the best approach is to write comment lines saying what steps you want the program to take to accomplish the task (in CS classes they used to refer to this as pseudo-code) , once you have the how figured out, fill in the code to actually do it, looking up the syntax for the language you want as needed.