One of the more useful concepts in scripting is keeping your data
separate from your code
as much as possible.
One of the primary ways to do this is to pre-define all of your file paths and other fixed data strings in variables at the top of the script, rather than embedding them in the script. It keeps the clutter down and makes things cleaner and easier to debug, as well as making them easier to alter without having to go through the whole script.
Specifically, the following three strings of yours should all be pre-configured as variables:
In addition, since the same ssh
command appears over and over with only minor variations, that makes it a perfect candidate for a function
. preconfigure the basic command at the top of the script, and call it with the proper options when the need arises.
Check out Scripting With Style
for more tips on how to write clean and robust code.