Last active
January 29, 2019 21:56
-
-
Save maestrojed/362f415ea740e1c335e0bfd1f8f0df36 to your computer and use it in GitHub Desktop.
Redirect Output from remote connection using a heredoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# sets some vars so the editor doesn't report errors | |
deployID="1234" # A custom ID retrived in our script, for demo, hardcard | |
logFile=$(date +%b-%d-%Y-%H-%M-%S)-$deployID".log" | |
projectPath=${PWD} | |
sshUser="maestrojed" | |
sshHost="maestrojed.example.com" | |
set -x | |
# redirect all output to the log, while still being verbose on the screen | |
exec > >(tee -i "$projectPath/deployments/logs/$logFile") | |
# do some stuff, a shortened example for this demo | |
cd temp | |
ls | |
# Now runs some commands on an SSH connection using a heredoc. | |
# I also want to redirect the output of these commands, run on the remote server, to my log file. So I capture it in a var $serverOutput | |
ssh -tt $sshUser@$sshHost <<EOF | |
pwd | |
ls | |
cd myDir/ | |
ls | |
exit | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment