我在for循环bash脚本中编写了一个expect脚本。在期望脚本期间满足条件时,脚本将退出并退出'命令。但是它会出现在bash脚本中并再次进行下一次迭代。如果我在bash脚本中提供break语句,它将影响所有条件。请建议我如何实现这一点。
for i in `cat /tmp/downtimehosts.txt`
do
{
y=$( expr $y + 1 )
j=$(echo $i | awk -F. '{print $1}')
host=$(cat /tmp/ipmon_host_db.txt | grep $j | awk '{print $4}')
ipmon=$(cat /tmp/ipmon_host_db.txt | grep $j | awk '{print $2}')
if [ $? -eq 0 ]
then
{
/usr/bin/expect -c "
spawn ssh $username@$ipmon
expect {
-re ".*Are.*.*yes.*no.*" {
send \"yes\r\"
exp_continue
}
"*?ssword:*" {
send \"$password\r\"
expect "password" {
send "quit\r"
exit
}
}}
expect "denied" {
send "quit\r"
exit
}
expect "~]$"
send \"sudo su -\r\"
expect "password"
send \"$password\r\"
expect "~]"
send \"/apps/bin/schedule-downtime.pl -v -h "$host" -d
"$his"\r\"
expect "~]"
send \"logout\r\"
expect "~]"
send \"logout\r\"
expect eof"
}
else
:
fi
}
done
在上面,如果密码错误,它必须退出expect脚本以及bash脚本。
答案 0 :(得分:2)
如果您的Fragment
脚本出现错误,请返回非零值,例如public class HomeFragment : Fragment
{
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your fragment here
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate(Resource.Layout.homelayout, container, false);
return view;
}
}
。
然后在expect
代码中,使用exit 23
检查结果。如果它不为零,则bash
离开循环:
$?