我有一个包含几个函数的shell脚本。我需要在两台不同的机器上运行它,每台机器需要运行n
次。我可以按照下面提到的方式调用函数并执行吗?还是有其他方法可以完成这个任务?
#!/usr/bash
execCommand () {
#few statements here
}
getStatus() {
#few statements here
}
main () {
execCommand
getStatus
}
$machine1="machine1"
$machine2="machine2"
$user="username"
$n=2
while [$n -le 2]
do
ssh $user@$machine1 'main'
sleep 100
ssh $user@$machine2 'main'
n=$n+1
done
main
。你必须通过ssh
连接发送所有内容。你也可以将文件复制到远程机器上,然后使用ssh执行它。 - fedorqui