0
我有一个脚本,我手动运行(比方说)mylogin
。但有一行需要以用户postgres
运行。如何作为特定用户运行一行bash shell脚本
什么是一个很好的方法来做到这一点?
没关系,如果我得到密码提示。我只是需要它以某种方式工作。
这里是我迄今为止...
~/reload_test_data.sh
#!/bin/bash
# Here's the part that needs to run as user `postgres`...
sudo su postgres
export PGDATA=/Library/PostgreSQL/9.4/data && pg_ctl -m fast restart
# And here we should go back to `mylogin`...
cd ~/projects/my_project
echo 'Dropping database'
bundle exec rake db:drop
# More stuff etc...
我使用Mac OS 10.12.1。
优秀。谢谢。 – Ethan