-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexec_morelist.sh
executable file
·92 lines (87 loc) · 2.72 KB
/
exec_morelist.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
start=`date +'%F %H:%M:%S'`
source_functions()
{
. conf/itennis.conf
. scripts/log_print
. scripts/exec_remote
}
source_functions
tmp_fifofile="/tmp/$.fifo"
CONF_LIST=/tmp/conf_list.$$
RESULT_ALL=/tmp/res_all.$$
CMDS_FILE=$2
mkfifo $tmp_fifofile # 新建一个fifo类型的文件
exec 6<>$tmp_fifofile # 将fd6指向fifo类型
rm $tmp_fifofile
grep -v "^#" $1 > ${CONF_LIST}
THREAD=`cat ${CONF_LIST} | wc -l`
for ((i=1;i<$THREAD+1;i++));do
echo
done >&6
if [[ "$3" = "y" ]];then
for ((i=1;i<$THREAD+1;i++))
do
{
read -u6
{
arr=(`sed -n ${i}p $CONF_LIST`)
grep -v "^#" ${CMDS_FILE} | while read line
do
echo "[`date`] exec_cmd_r $REMOTE_PORT $REMOTE_TIMEOUT ${arr[0]} ${arr[2]} ${arr[3]} \"$line\"" | tr -d '\r' >> /var/log/iTennis/${arr[0]}.log
exec_cmd_r $REMOTE_PORT $REMOTE_TIMEOUT ${arr[0]} ${arr[2]} ${arr[3]} "$line" &>> /var/log/iTennis/${arr[0]}.log
if [[ $? = 0 ]];then
log INFO "${line} execute in ${arr[0]} success"
else
log ERROR "${line} execute in ${arr[0]} failed"
fi
done
if [[ $? = 0 ]];then
log WARN "The current ${i} , ${arr[0]} is finshed" >> $RESULT_ALL
else
log ERROR "The current ${i} , ${arr[0]} is execute failed , pleace check it" >> $RESULT_ALL
fi
} || {
log ERROR "thread error"
}
echo >&6
} &
done
else
for ((i=1;i<$THREAD+1;i++))
do
{
read -u6
{
arr=(`sed -n ${i}p $CONF_LIST`)
grep -v "^#" ${CMDS_FILE} | while read line
do
echo "[`date`] exec_cmd_r $REMOTE_PORT $REMOTE_TIMEOUT ${arr[0]} ${arr[2]} ${arr[3]} \"$line\"" | tr -d '\r' >> /var/log/iTennis/${arr[0]}.log
exec_cmd_r $REMOTE_PORT $REMOTE_TIMEOUT ${arr[0]} ${arr[2]} ${arr[3]} "$line"
if [[ $? = 0 ]];then
log INFO "${line} execute in ${arr[0]} success"
else
log ERROR "${line} execute in ${arr[0]} failed"
fi
done
if [[ $? = 0 ]];then
log WARN "The current ${i} , ${arr[0]} is finshed" >> $RESULT_ALL
else
log ERROR "The current ${i} , ${arr[0]} is execute failed , pleace chect it" >> $RESULT_ALL
fi
} || {
log ERROR "thread error"
}
echo >&6
}
done
fi
wait
exec 6>&-
end=`date +'%F %H:%M:%S'`
log INFO "--------------------------------------------------------------"
sort -n -k 6 $RESULT_ALL
log INFO "Begin time:$start , End time: $end"
log INFO "--------------------------------------------------------------"
rm /tmp/*.$$
exit 0