Sudo: menjalankan command di script: Difference between revisions

From OnnoCenterWiki
Jump to navigationJump to search
Onnowpurbo (talk | contribs)
Created page with "sumber: https://askubuntu.com/questions/425754/how-do-i-run-a-sudo-command-inside-a-script It is rarely a good idea to have sudo inside scripts. Instead, remove the sudo f..."
 
Onnowpurbo (talk | contribs)
No edit summary
Line 1: Line 1:
sumber: https://askubuntu.com/questions/425754/how-do-i-run-a-sudo-command-inside-a-script
sumber: https://askubuntu.com/questions/425754/how-do-i-run-a-sudo-command-inside-a-script


 
Cara yang normal tambahkan sudo sebelum menjalankan script
 
 
It is rarely a good idea to have sudo inside scripts. Instead, remove the sudo from the script and run the script itself with sudo:


  sudo myscript.sh
  sudo myscript.sh


That way, all commands within the script will be run with root privileges and you only need to give the password once when launching the script. If you need a particular command within the script to be run without sudo privileges, you can run it as a regular user with (thanks Lie Ryan):
Atau jika hanya salah satu command saja, bisa


  sudo -u username command  
  sudo -u username command  


The space is irrelevant, it should not affect anything, there is always a space between a command and its arguments.
Atau kalau mau memaksa, bisa


exec sudo su -c "perintah"





Revision as of 15:07, 16 December 2018

sumber: https://askubuntu.com/questions/425754/how-do-i-run-a-sudo-command-inside-a-script

Cara yang normal tambahkan sudo sebelum menjalankan script

sudo myscript.sh

Atau jika hanya salah satu command saja, bisa

sudo -u username command 

Atau kalau mau memaksa, bisa

exec sudo su -c "perintah"


Referensi