zoukankan      html  css  js  c++  java
  • 从指定csv文件根据用户名批量导入邮件及*信息到数据库

    #局方一共有200多条用户信息需要添加在web界面,写此脚本目的是为了给本地外籍员工减少工作量。后因据说售后技术支持没权限写脚本操作数据库,尤其是增减操作,于是当作练手,并记录于此。

    #需将客户提供的excel文件转化为.csv格式

    #需切换到postgres用户进行脚本运行

    #!/bin/bash

    declare -i row_num=1

    cat usr_info_list.csv | while read line
    do
           if test $row_num -eq 1
    then
           row_num+=1
    else
           user_name=$(awk -F ""*,"*" '{print $1}' usr_info_list.csv | sed -n $row_num'p')
           email=$(awk -F ""*,"*" '{print $2}' usr_info_list.csv | sed -n $row_num'p')
           phone_number=$(awk -F ""*,"*" '{print $3}' usr_info_list.csv | sed -n $row_num'p')
           operatorid=$(psql -U zxdbm_830 -d zxin -c "select operatorid from oper_information where opername='$user_name';" )
           ARR_OPERATORID=($operatorid)
          #judge whether username is valid
          if test ${ARR_OPERATORID[2]} = '(0'
          then
                  echo "user:$user_name is not exist"
         else
                  echo "${ARR_OPERATORID[2]}"
                  psql -U zxdbm_830 -d zxin -c "update oper_information set telephone=$phone_number where opername='$user_name';"
                  # judge whether the email exist,if exist then update,else insert.
                  mailbox=$(psql -U zxdbm_830 -d zxin -c "select mailbox from oper_mail where operatorid=${ARR_OPERATORID[2]};" )
                 ARR_MAILBOX=($mailbox)
                 if test ${ARR_MAILBOX[2]} = '(0'
                 then
                        psql -U zxdbm_830 -d zxin -c "insert into oper_mail values(${ARR_OPERATORID[2]},'$email');"
                 else
                        psql -U zxdbm_830 -d zxin -c "update oper_mail set mailbox='$email' where operatorid=${ARR_OPERATORID[2]};"
                 fi
          fi
          row_num+=1
    fi
    done

    全力以赴不留遗憾
  • 相关阅读:
    sql学习2----函数
    网络相关命令
    网络相关概念
    linux学习(2)--指令
    linux学习(1)--基本知识
    Linux学习技巧
    VMware安装Linux
    接口测试
    app测试--DDMS的使用
    app测试--性能测试DDMS
  • 原文地址:https://www.cnblogs.com/zhonghaijing/p/14942806.html
Copyright © 2011-2022 走看看