Skip to content

Instantly share code, notes, and snippets.

@dgpro
Created April 1, 2019 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgpro/ced054777b2811399bef891aa49a34ec to your computer and use it in GitHub Desktop.
Save dgpro/ced054777b2811399bef891aa49a34ec to your computer and use it in GitHub Desktop.
SSH Script to automatically run a number of commands on remote servers. E.g. to restart Laravel instance
#!/bin/bash
# exit if any of the commands fail
set -e
# import config with IP addresses
source ${BASH_SOURCE[0]%/*}/ip.conf
echo -e "Connecting to IP:$laravel";
ssh root@$worker -t "cd /var/www/ &&
php artisan down &&
php artisan config:cache &&
sudo service php7.1-fpm restart &&
php artisan up"
# can repeat for multiple servers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment