社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
将数据库名,写入1脚本中
#vi 1
#!/bin/bash
for i in `cat b`
do
psql xc_hzh_nanxun -c "alter table $i owner to hzhnanxun"
done
使用dt,查看数据库里面所有的表
#vi 11.txt #将数据库里面的表复制到11.txt里面(也可以直接写成11)
public | resource_url | table | xchzhlinan
public | role | table | xchzhlinan
public | send_ets_focusinfo | table | xchzhlinan
public | site_inner_outer | table | xchzhlinan
public | site_post_info | table | xchzhlinan
public | spid_article | table | xchzhlinan
public | spid_article_content | table | xchzhlinan
public | spid_article_reply | table | xchzhlinan
public | spid_task | table | xchzhlinan
public | spid_task_account | table | xchzhlinan
public | spid_task_syn | table | xchzhlinan
public | spid_task_syn_all | table | xchzhlinan
$awk ‘{print $3}’ 11.txt #只显示出打印的表名
awk ‘{print $3}’ 11.txt>12.txt #将11.txt中的表名导入到12.txt中
#cat 12.txt #查看b脚本是否只有表名
postgres@shhkfys:~$ cat b #查看脚本中,需要修改的表名。
postgres@shhkfys:~$ cat 1 #核对a脚本里面,需要修改的数据库名和表名,是否有误。
postgres@shhkfys:~$ bash -x 1 #执行脚本1,更改数据库表的用户名
查看脚本执行结果。查看用户是否有权限查看数据库表的内容
postgres@shhkfys:~$ psql
psql.bin (9.4.1)
Type "help" for help.
No entry for terminal type "xterm";
using dumb terminal settings.
postgres=# c xc_hzh_nanxun
You are now connected to database "xc_hzh_nanxun" as user "postgres".
xc_hzh_nanxun=# c - hzhnanxun
Password for user hzhnanxun:
You are now connected to database "xc_hzh_nanxun" as user "hzhnanxun".
xc_hzh_nanxun=> dt
xc_hzh_nanxun=> select * from cust_site;
修改完成。
#!/bin/bash
for i in `cat x`
do
weixin=',weixinStorer_6000'
psql yun -c 'update asset_server set describe=CONCAT(describe,'"'$weixin'"') where ip='"'$i'"';'
done
x内容如下:
postgres@hdslave20:~$ cat x
1.1.1.1
1.1.1.2
1.1.1.3
1.1.1.4
1.1.1.5
1.1.1.6
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!