【发布时间】:2018-11-29 11:51:11
【问题描述】:
假设我有一堆命令要在我的本地机器上执行,还有一堆其他命令要在远程主机上执行。例如:
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
}
关于如何使用 shell 脚本实现所有这些的任何想法?
【问题讨论】: