Say I have a bunch of commands that I'd like to execute on my local machine and bunch of others on the remote host. For example:
execute_locally_then_remotely() {
# Things I want to execute locally
foo --bar
foo --baz
scp filename.gz $1:/tmp
ssh $1
# Execute these commands on remote host
gunzip -xvf /tmp/filename.gz
rm -f /tmp/filename.gz
sudo -su otheruser
# Bunch of other commands I'd like to execute as a different user on remote host
foobar filename
# Exit back to local shell and execute following commands here:
ls
}
Any ideas on how to achieve all this using a shell script?