前端之家收集整理的这篇文章主要介绍了
通过ssh 获取远程服务器sqlite数据库表信息,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/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,说明执行正确