Last active
October 8, 2019 20:29
-
-
Save gugarosa/08fc418b138c847d26000a9a18ac13dc to your computer and use it in GitHub Desktop.
Logs into a host via SSH, runs a command and dumps the file to local machine via SFTP.
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
#!/bin/bash | |
# User to enter the host | |
USER=username | |
# Script to run in host | |
# In this case, we will be dumping the process my memory usage order | |
SCRIPT="ps aux --sort -%mem" | |
# List of hosts | |
HOSTS="host@host.com" | |
# For every host in the list | |
for HOST in ${HOSTS}; | |
do | |
# Access the host with SSH and runs the script, producing an output file | |
ssh -l ${USER} ${HOST} "${SCRIPT} > ${HOST}.txt" | |
# Acess the host with SFTP | |
sftp ${USER}@${HOST} <<EOF | |
get ${HOST}.txt | |
EOF | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment