用TTL,发送10个数组里面的命令
时间: 2024-03-20 07:43:54 浏览: 9
TTL 脚本本身不会发送命令,它只能检查主机的可达性。如果您想通过网络发送命令,则需要使用其他工具,如 SSH 或 Telnet。
以下是一个使用 SSH 发送命令的示例脚本,在本地主机上循环遍历一个数组,并在远程主机上执行每个命令:
```bash
#!/bin/bash
# SSH Command Script
# Usage: ssh_cmd.sh <remote_host> <username> <password> <commands_file>
if [ "$#" -ne 4 ]; then
echo "Usage: $0 <remote_host> <username> <password> <commands_file>"
exit 1
fi
remote_host=$1
username=$2
password=$3
commands_file=$4
# Loop through commands file
while read cmd; do
# Send command via SSH
sshpass -p $password ssh $username@$remote_host "$cmd"
done < $commands_file
```
在上面的脚本中,我们需要传递远程主机的 IP 地址、用户名、密码以及包含要执行的命令的文件路径。然后,我们使用 sshpass 工具来自动输入密码并使用 ssh 命令连接到远程主机。在循环中,我们遍历命令文件中的每个命令,并使用 ssh 命令将其发送到远程主机。
注意:使用明文密码是不安全的做法,因此在实际生产环境中,您应该使用 SSH 密钥对来进行身份验证。