Add readme
This commit is contained in:
71
README.md
71
README.md
@@ -1,3 +1,70 @@
|
||||
# script-executer
|
||||
# Script Executer
|
||||
|
||||
This app will execute scripts in a folder, or just inside of text files, and stop when errors are detected
|
||||
## Why does this project exist?
|
||||
|
||||
Managing and automating the execution of multiple shell scripts can be error-prone and tedious, especially for tasks like backups, system setup, or batch operations. This project provides a simple, reliable way to run one or more shell script files (or lists of shell commands) in a controlled, repeatable manner. It ensures that scripts are executed in order, stops on errors, and supports directory changes within scripts.
|
||||
|
||||
## How does it work?
|
||||
|
||||
The `runner` Go program takes a path to either a single script file or a directory containing `.sh` files:
|
||||
|
||||
- If given a directory, it finds all `.sh` files, sorts them alphabetically, and executes them one by one.
|
||||
- If given a file, it executes the commands in that file.
|
||||
- Each script is read line by line. Blank lines and lines starting with `#` are ignored.
|
||||
- The special command `cd <dir>` is supported, allowing scripts to change the working directory for subsequent commands.
|
||||
- If any command fails, execution stops immediately and the error is reported.
|
||||
|
||||
## Why use this for backups and other scripts?
|
||||
|
||||
- **Reliability:** Ensures that all commands succeed before moving on, so you know your backup or batch process completed as expected.
|
||||
- **Order:** Runs scripts in a predictable, sorted order, which is important for incremental backups or multi-step processes.
|
||||
- **Directory Management:** Supports `cd` commands, so you can organize scripts that operate in different locations.
|
||||
- **Automation:** Great for cron jobs, scheduled tasks, or any workflow where you want to automate a series of shell commands.
|
||||
- **Transparency:** Prints each command as it runs, making it easy to debug and audit your backup or script process.
|
||||
|
||||
## How to use
|
||||
|
||||
### 1. Build the runner
|
||||
|
||||
```sh
|
||||
go build -o runner main.go
|
||||
```
|
||||
|
||||
### 2. Prepare your scripts
|
||||
|
||||
- Place your `.sh` files in a directory (e.g., `backup-scripts/`).
|
||||
- Or, create a single file with one command per line.
|
||||
- Use `cd <dir>` to change directories within your scripts if needed.
|
||||
|
||||
Example script (`backup.sh`):
|
||||
|
||||
```sh
|
||||
# Backup home directory
|
||||
cd ~/Documents
|
||||
tar czf /tmp/backup-docs.tar.gz .
|
||||
|
||||
# Backup pictures
|
||||
cd ~/Pictures
|
||||
tar czf /tmp/backup-pics.tar.gz .
|
||||
```
|
||||
|
||||
### 3. Run the runner
|
||||
|
||||
To run a single script:
|
||||
|
||||
```sh
|
||||
./runner path/to/backup.sh
|
||||
```
|
||||
|
||||
To run all `.sh` scripts in a directory (in sorted order):
|
||||
|
||||
```sh
|
||||
./runner path/to/backup-scripts/
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- The runner uses `bash` to execute commands.
|
||||
- The working directory resets before each script file is executed.
|
||||
- If any command fails, execution stops immediately.
|
||||
- Useful for backups, system setup, test automation, and more.
|
||||
|
||||
Reference in New Issue
Block a user