业务需要:不同用户倒入数据,并发执行
受限:因为shell顺序执行,如果某条命令不执行完成,后续循环语句在等待
具体实现:nohup在后台执行,跳过当前命令必须执行结束限制
脚本示例:
#!/bin/bash
for i in {1…100}
do
{
/usr/bin/expect <<EOF
spawn 工具倒入命令 $i
set timeout 1800
expect {
“Password :” {send “密码\r”;exp_continue}
}
EOF
}&
done
总结:
错误.直接在shell中写函数(实现业务逻辑)
执行报错:nohup :failed to run commond 函数 ;no such file or directory .
根因分析:nohup 正确使用 no hang up 不挂断
nohup Commond [arg…] [&]
eg:nohup bash main.sh &
nohup ./main.sh &
nohup bash main.sh A B C &
nohup bash main.sh > test.log &
Shell 中后台实现并发原理:
函数格式,写成逻辑命令 以{逻辑}&.
{
逻辑代码
}&