This paper is a very good primer on how to organize a project. The following is a simplification that is a good start for building an automated script.
1. File structure
2. Driver (runall.sh) scripts
The idea of a runall.sh script is to have a wrapper script that runs everything, from cleaning and prepping your data, all intermediate steps and the final results. This way you can easily rerun a experiment/project with new data.