What does `cat file | ssh host 'cat - >file'` do?

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

0

1 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" | ssh opens the file and pipes it to the ssh process, a less efficient way of letting the shell do the same with

    <"$NGINX_CONF" ssh

    The part in single quotes holds the command(s) to run on the remote machine. ssh forwards its input (i.e. the file content) to this command.

  • cat - > /tmp/ironscales redirects cat’s (= ssh’s) standard input (-) to the specified file
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like