spatie/scotty
Scotty is a beautiful SSH task runner for executing scripted tasks on remote servers. Define tasks in a Scotty.sh file (bash with annotations), run them with clear output, and use it as a drop-in, Envoy-compatible alternative for deploys and ops.
Let's get Scotty up and running. By the end of this page, you'll have created a Scotty file and run your first task on a remote server.
You'll need Scotty installed and SSH access (with key-based authentication) to a server you want to run commands on.
In your project root, run:
scotty init
Choose the bash format when prompted and enter your server's SSH connection string (for example deployer@your-server.com). Scotty creates a Scotty.sh file for you.
You can also create the file by hand. Just add a Scotty.sh in your project root:
#!/usr/bin/env scotty
# [@servers](https://github.com/servers) remote=deployer@your-server.com
Replace deployer@your-server.com with your actual server.
A task is a bash function with a # [@task](https://github.com/task) annotation above it. The on: parameter tells Scotty which server to run it on.
Let's add a simple task that checks the server's uptime:
#!/usr/bin/env scotty
# [@servers](https://github.com/servers) remote=deployer@your-server.com
# [@task](https://github.com/task) on:remote
checkUptime() {
uptime
df -h /
}
scotty run checkUptime
Scotty connects to your server over SSH, runs the commands, and streams the output back. That's your first manual SSH step, automated.
Now let's add something more useful. Say you have a Laravel app at /var/www/my-app on the server:
#!/usr/bin/env scotty
# [@servers](https://github.com/servers) remote=deployer@your-server.com
# [@task](https://github.com/task) on:remote
checkUptime() {
uptime
df -h /
}
# [@task](https://github.com/task) on:remote
pullCode() {
cd /var/www/my-app
git pull origin main
}
# [@task](https://github.com/task) on:remote
clearCache() {
cd /var/www/my-app
php artisan cache:clear
php artisan config:clear
php artisan view:clear
}
You can run each one individually with scotty run pullCode or scotty run clearCache.
Running tasks one by one isn't much better than doing it by hand. A macro lets you run them in sequence with a single command. Add this near the top of your file, right after the # [@servers](https://github.com/servers) line:
# [@macro](https://github.com/macro) deploy pullCode clearCache
Now:
scotty run deploy
If any task fails, Scotty stops right there so you can investigate. You'll see a summary table at the end with timing for each step.
Before running a deploy for real, use the doctor command to check that everything looks good:
scotty doctor
This validates your Scotty file, tests SSH connectivity, and checks that tools like PHP, Composer, and Git are available on the server.
Here's what your Scotty.sh looks like now:
#!/usr/bin/env scotty
# [@servers](https://github.com/servers) remote=deployer@your-server.com
# [@macro](https://github.com/macro) deploy pullCode clearCache
# [@task](https://github.com/task) on:remote
checkUptime() {
uptime
df -h /
}
# [@task](https://github.com/task) on:remote
pullCode() {
cd /var/www/my-app
git pull origin main
}
# [@task](https://github.com/task) on:remote
clearCache() {
cd /var/www/my-app
php artisan cache:clear
php artisan config:clear
php artisan view:clear
}
How can I help you explore Laravel packages today?