#!/bin/bash
ip=1
while [ $ip -lt 255 ]
do
echo "#####################################---$ip">>statusinfo
echo "------------------username:">>statusinfo
echo "hadoop">>statusinfo
echo "------------------ip:">>statusinfo
echo "192.168.150.$ip">>statusinfo
echo "------------------hostname:">>statusinfo
expect -c "
set timeout 25
expect *
spawn rsh 192.168.150.$ip -l hadoop hostname>>statusinfo
expect "password"
send "hadoop\r"
"
sleep 2
ip=`expr $ip + 1`
done
My goal is through a cycle , access to 150 segments of all the machine's host name and the corresponding ip address, via rsh remote machine , the hostname command and then redirect the results to the machine statusinfo file, but whenever the shell to run to enter the password, and then directly enter the next cycle , there is no hostname command , which is why ah ? Great God ?
all day, and still like this !
------ Solution ---------------------------------------- ----
I changed the line rhs let temp [spawn rsh 192.168.152. $ ip-l hadoop hostname], the result is still the temp effect obtained seem process spawn numbers.
There are other ways to do ?
This rsh is how ah ? Redirect loop is not effective ?
set results $ expect_out (buffer)
------ For reference only ------------------------- --------------
Why ah this is ? I think the logic that are not wrong ?
------ For reference only ---------------------------------------
in the shell environment , a single execution rsh 192.168.150. $ ip-l hadoop hostname >> statusinfo time , without any problems , circulatory problems will emerge , depressed !
Why ah ?
------ For reference only ---------------------------------- -----
expect is not the same, reference examples:
mainly set results $ expect_out (buffer)
# Send the prebuilt command, and then wait for another shell prompt.
send "$my_command\r"
expect "%"
# Capture the results of the command into a variable. This can be displayed, or written to disk.
set results $expect_out(buffer)
------ For reference only ----------------------------------- ----
I changed the line rhs let temp [spawn rsh 192.168.152. $ ip-l hadoop hostname], the result is still the temp effect obtained seem process spawn numbers.
There are other ways to do ?
This rsh is how ah ? Redirect loop is not effective ?
没有评论:
发表评论