主脚本
#!/bin/bash
# do_scan.sh
if [ $# -lt 2 ]
then
echo "bash $0 task_script hostlist [thread_num] [parameters]"
exit
fi
function logit
{
echo "[`date +%F-%T`] $@"
}
mkfifo ff
exec 4<>ff
unlink ff
task=$1
list=$2
thread=$3
if [ "$thread" == "" ]
then
thread=50
fi
if [ $thread -ge 2000 ]
then
thread=2
fi
rm -rf log
mkdir log
>./donelist
for((i=0;i<$thread;i++))
{
echo >&4;
}
for i in `cat $list`
do
logit "starting $task $i:$file $para"
(bash $task $i &>log/$i; echo $i >>./donelist;echo >&4) &
read <&4
done
wait
echo >&4-
echo "Run over."
命令脚本
#!/bin/bash
# task_script.sh
SSH="ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectionAttempts=2 -o ConnectTimeout=10 -n"
mac=$1
#echo $mac
#run_date=`date +%Y%m%d -d"-1 days"`
$SSH xxx@$mac "cat xxx"
获取机器列表
#!/bin/sh
# list.sh
bns=(
"ae-app-xxx.www.nj"
)
for idc in ${bns[@]};
do
get_instance_by_service $idc
done
执行
sh list.sh > list
sh do_scan.sh task_script.sh list 50