我有一个bash脚本,它有以下两个命令:
ssh host tail -f /some/file | awk ..... > /some/file &
ssh host tail -f /some/file | grep .... > /some/file &
Run Code Online (Sandbox Code Playgroud)
如何将两个命令的输出定向到同一个文件中.
我在两个目录中都有日志文件,为简单起见,我将依次调用目录1和目录2。
假设用户输入了位于dir1中的file.log,我应该在-f后面加上dir1和dir2中除file.log之外的所有文件。有人可以帮我吗
ssh host 'find /path/to/a/log -maxdepth 1 -type f -name "file*" -name "*.log" ! -name "$1" -print0 -exec tail {} \;' > /home/pl-${node}.log
ssh host 'find /path/to/a/log -maxdepth 1 -type f -name "file*" -name "*.out" ! -name "$1" -print0 -exec tail {} \;' > /home/pl-${node}.out
Run Code Online (Sandbox Code Playgroud)
节点只是存储1和2的变量。当我输入./test file-1.log时,输出为:
pl-1.log
Oct 21 09:15 pl-1.out
Oct 21 09:15 pl-2.log
Oct 21 09:15 pl-2.out
Run Code Online (Sandbox Code Playgroud)
如您所见,即使我将file-1.log指定为不带参数,也将所有文件都带尾$1。
我想使用 ssh 密钥认证。我有一个包含以下内容的文件:
ip位置
ip位置
等等
我有一个 bash 脚本如下:
declare -A mylist
declare -A myarray
i=1
while read line ; do
mylist[$i]=$(echo $line | awk '{print $1}')
myarray[$i]=$(echo $line | awk '{print $2}')
((i++))
done <file.conf
for ip in "${mylist[@]}"; do
for location in "${myarray[@]}" ; do
ssh ${ip} tail -f ${location} > /home/log_${ip} 2>/dev/null &
done
done
Run Code Online (Sandbox Code Playgroud)
当我这样做时,它一直要求我输入密码。我不知道如何生成密钥,请告诉我步骤。