Leons Aleksandrovs 976c248c4f Add readme
2025-08-11 22:39:58 +03:00
2025-08-10 20:57:34 +03:00
2025-08-10 21:53:27 +03:00
2025-08-11 22:34:10 +03:00
2025-08-11 22:39:58 +03:00

Script Executer

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

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):

# 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:

./runner path/to/backup.sh

To run all .sh scripts in a directory (in sorted order):

./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.
Description
This app will execute scripts in a folder, or just inside of text files, and stop when errors are detected
Readme 35 KiB
Languages
Go 100%