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
|
#!/bin/bash # create by lhb # date 2013-10-29 # ssh get romote server sqlite table info auto_smart_ssh () { expect -c " set timeout -1;
spawn ssh -o StrictHostKeyChecking=no $2 ${@:3};
expect {
*assword:* {send -- $1\r;
expect {
*denied* { exit 2;}
eof }
}
eof { exit 1;}
}
"
return $?
}
list= "/home/lhb/list.txt"
if [ -f "$list" ]; then
rm $list
fi touch $list
db_path= "/home/lhb/data/sqlite.db"
hosts=( "192.168.38.50" "192.168.38.51" "192.168.38.52" )
user= "lhb"
passwd = "password"
cmd= "sqlite3 $db_path 'select video_id,video_name from dopool_video'"
#sqlite3 /home/lhb/data/sqlite.db 'select video_id,video_name from dopool_video' >> $list #sqlite3 /home/lhb/data/sqlite.db 'select video_id,video_name from dopool_video' for host_ip in ${hosts[@]}
do #auto_smart_ssh $passwd $user@$host_ip $cmd | grep "^[0-9]*|" auto_smart_ssh $ passwd $user@$host_ip $cmd | grep "^[0-9]*|" >> $list
done #auto_smart_ssh '$passwd' dopool@192.168.38.156 "sqlite3 /home/lhb/data/sqlite.db 'select * from dopool_video'" >> $list #echo -e "\n---Exit Status: $?" #返回0,说明执行正确 |
本文转自birdinroom 51CTO博客,原文链接:http://blog.51cto.com/birdinroom/1403830,如需转载请自行联系原作者