加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

我可以在bash脚本中运行’su’吗?

发布时间:2020-12-15 18:51:56 所属栏目:安全 来源:网络整理
导读:我可以在脚本中改变/ su用户吗? if [ "$user" == "" ]; then echo "Enter the table name"; read userfigunzip *chown postgres *su postgres dropdb $userpsql -c "create database $user with encoding 'unicode';" -U dbname template1psql -d $user -f
我可以在脚本中改变/ su用户吗?
if [ "$user" == "" ]; then
  echo "Enter the table name";
  read user
fi

gunzip *
chown postgres *
su postgres 
dropdb $user
psql -c "create database $user with encoding 'unicode';" -U dbname template1
psql -d $user -f *.sql
你可以,但是bash不会以后续的命令运行postgres.相反,做:
su postgres -c 'dropdb $user'

-c标志以用户身份运行命令(见man su).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读