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