this is the script:
#!/bin/bash
usage() { echo "deploy-nginx.sh --production|--staging"
}
case "$1" in --staging) NGINX_CONF="conf/nginx-staging"; HOST="staging" ;; --production) NGINX_CONF="conf/nginx-production"; HOST="production" ;; *) usage; exit 2;
esac
cat "$NGINX_CONF" | ssh -F conf/ssh_config "$HOST" ' cat - > /tmp/ironscales sudo cp /etc/nginx/sites-available//tmp/myapp{,-$(date +%Y%m%d-%H%M%S)} sudo mv /tmp/myapp /etc/nginx/sites-available/myapp sudo service nginx reload
'I understand the usage function, and the case switch
what I don't understand at all, is the part following cat
01 Answer
The part following cat "$NGINX_CONF" serves to copy the file from the $NGINX_CONF variable to the remote machine using ssh and perform other actions.
cat "$NGINX_CONF" | sshopens the file and pipes it to thesshprocess, a less efficient way of letting the shell do the same with<"$NGINX_CONF" sshThe part in single quotes holds the command(s) to run on the remote machine.
sshforwards its input (i.e. the file content) to this command.cat - > /tmp/ironscalesredirectscat’s (=ssh’s) standard input (-) to the specified file