Skip to content

Instantly share code, notes, and snippets.

@fmtarif
Created July 25, 2021 08:37
Show Gist options
  • Save fmtarif/ca6bf3cb5c716faabd4d45238bcaa324 to your computer and use it in GitHub Desktop.
Save fmtarif/ca6bf3cb5c716faabd4d45238bcaa324 to your computer and use it in GitHub Desktop.
#scripts #cli #devops a local script to keep within project dir in git and run ssh cmds remotely
#! /usr/bin/env bash
DIR="$( dirname "$_" )"
DIR=${DIR/\./} #if script invoked like ./index then remove the dot
commands=("sshprod", "sshproddeploy")
echo ${commands[@]}
show_commands() {
echo 'Available commands:
sshprod
sshproddeploy
'
}
#if [ ${commands[@]} | grep -o "sshproddeploys" | wc -w ]; then
#echo 'yes'
#else
#echo 'no'
#fi
if [ $# -gt 0 ]; then
if [ "$1" == "sshprod" ]; then
shift 1
ssh "$@" -F $DIR/sshconfig prod
fi
if [ "$1" == "sshproddeploy" ]; then
shift 1
ssh "$@" -F $DIR/sshconfig prod -t "cd /project/path && git pull"
fi
else
show_commandsode
fi
Host prod
Hostname actual_host_here
StrictHostKeyChecking no
User username_here
Port 22
CheckHostIP no
IdentityFile ./id_rsa_itc_dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment