經過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,說明執行正確
相關文章
相關標籤/搜索