我正在设置一个解决方案来从蜂窝路由器捕获信息。在我的脚本中,我有一个 main.sh
根据路由器型号启动其他文件 (*.sh)。
因此,如果我想捕获有关 cisco 路由器的信息,我会执行 main.sh
,它正在执行 InformationCisco.sh
。
在最后一个 shell 文件中,我必须读取一个值,但是
read -p
or
echo -n then read
不工作。
主程序
./InformationCisco.sh
编辑: InformationCisco.sh
sshpass -p "$MDPssh" ssh -o StrictHostKeyChecking=no admin@"$IPaddress" "cat /proc/net/arp" > "$MACtxt"
testMAC=$(awk 'NR==3{print $4}' $MACtxt | cut -d ' ' -f23)
if [ -z "$testMAC" ]; then
MacAddressPlayer=$(awk 'NR==2{print $4}' $MACtxt | cut -d ' ' -f23)
echo "MAC address Player : $MacAddressPlayer"
else
echo "2 MAC address in ARP"
echo "You have to find the correct MAC address for the player"
cat $MACtxt
read -p "Enter the right MAC address : " MacAddressPlayer
MAC_Choice $typeMAC
echo "MAC address Player : $MacAddressPlayer"
fi
我读取路由器的 ARP 表以捕获与其连接的设备。为此,我使用 sshpass,我可以在其中输入我的密码(不用担心我的密码不清楚,这只是一个简化)。 在第二个运行的 shell 文件中时,读取功能不会停止。
我应该更改什么以便读取等待输入?
最佳答案
在您的上下文中,某些字符 \n
可能已经被发送到进程的标准输入,并且 read -p
会立即使用它。
关于linux - 如何从 bash 中的第二个文件 sh 中读取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56867696/