shell脚本链接数据库导出数据

来源:互联网 发布:java实现web服务器 编辑:程序博客网 时间:2024/06/06 03:52
#!/bin/bash#变量定义  #服务器域名hostname="abc"; #端口号prot="5154";#用户名user="bidding";#密码password="C01";  #数据库名dbname="bidding_promotion"; FilePath1="/opt/lsn/SecondCateIds.log";#若文件存在,则删除文件if [ -f ${FilePath1} ]; then    rm ${FilePath1}fi#创建文件touch ${FilePath1};TIME1=$(date "+%Y-%m-%d %H:%M:%S") echo -e "\n\n========================"${TIME1}" start handle!\n"echo -e '-h'${hostname} '-P'${prot} '-u'${user} '-p'${password} '-D'${dbname} '-e"'${sqlstr}'"', #从数据库promotion中读取cateWhiteList表信息--skip-column-names:去掉表头信息sqlstr="select cate_id from cate_white_list where cate_type=2 and ad_source=1 and is_open=1 and category_id in(9224,13941)";mysql -h${hostname} -P${prot} -u${user} -p${password} -D${dbname} --skip-column-names -e"${sqlstr}" > ${FilePath1}   if [ $? -ne 0 ]; then    echo "读取表失败"    exit 1fi