Difference between revisions of "Sudo: menjalankan command di script"

From OnnoWiki
Jump to navigation Jump to search
(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...")
 
 
(4 intermediate revisions by the same user not shown)
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
  
 +
sudo myscript.sh
  
 +
Atau jika hanya salah satu command saja, bisa
  
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 -u username "perintah"
  
sudo myscript.sh
+
Atau kalau mau memaksa, bisa
  
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):
+
exec sudo su -c "perintah"
  
sudo -u username command
 
  
The space is irrelevant, it should not affect anything, there is always a space between a command and its arguments.
+
===Jika di tanya password===
  
 +
Tambahkan script
  
 +
echo passwordsudonya | sudo -S 'script.sh'
  
 
==Referensi==
 
==Referensi==
  
 
* https://askubuntu.com/questions/425754/how-do-i-run-a-sudo-command-inside-a-script
 
* https://askubuntu.com/questions/425754/how-do-i-run-a-sudo-command-inside-a-script
 +
 +
 +
==Pranala Menarik==
 +
 +
* [[ssh]]

Latest revision as of 10:45, 17 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 "perintah"

Atau kalau mau memaksa, bisa

exec sudo su -c "perintah"


Jika di tanya password

Tambahkan script

echo passwordsudonya | sudo -S 'script.sh'

Referensi


Pranala Menarik