I am developing a application which requires the execution of terminal commands.I am using “Do Shell SCript” to execute the commands.The code is use is
do shell script “sudo cp /etc /etc1” .This command prompts a password .my problem is
- When i write a script is it possible to disable the password prompt.
- The above command does not prompt for password in one machine and in another machine i am testing it prompts.
Can anyone pls tell me what mite be the problem.
Thanks in Advance
- There is no need to disable the sudo password, you can store the password in your script (not recommended, but you can)
do shell script "sudo cp /etc /etc1" password "your-password" with administrator privileges
Does copying the /etc directory really require a password?
- Are you logged in as ‘root’ on the other machine? Also, ‘sudo’ has a timestamp of 5 minutes which may be why it appears to working on one machine and not the other.
See “man sudo” and “man sudoers” in the terminal.app for more info.
Thanks for the reply.I used the command without success.i m using applescript to configure stunnel in my machine.the script i use is
do shell script “cd;sudo stunnel -c -p stunnel.pem localhost:139 -r 220.127.116.11:3000 password " & variable & " with administrator privileges”
Can you pls tell me where i m going wrong .
yes, when using sudo, yo can only issue one command in do shell script. There is a technote @ Apple.com about using ‘do shell script’ and ‘sudo’, but I’ve not been able to find it.
I don’t know if this is the technote that Jean-Baptiste is referring to but it covers a lot of ground.
TN2065 - do shell script in AppleScript
The idea I gave might as well be a remeberance of what was said on a mailing list
I’m not familiar with ‘stunnel’, but your command has a “cd;” in front of the “sudo stunnel -c” command. You can use the semicolon ( ; ) to separate commands on the same line, but you are ‘cd’ing’ to the command “stunnel -c” which should give you an error. Also the syntax is incorrect for the password part of your script…
If ‘stunnel’ is not in your executable path, then you should use a path relative to the command
do shell script "sudo /path/to/stunnel -c -p stunnel.pem localhost:139 -r 18.104.22.168:3000" password """ & variable & """ with administrator privileges
Question, why are you using a variable for the password? If you have to type in a password somewhere, why don’t you let the System handle that. Like this…
sudo stunnel -c -p stunnel.pem localhost:139 -r 22.214.171.124:3000" with administrator privileges
You don’t use sudo AND ‘with administrator privileges’
‘with administrator privileges’ runs the specified command as root, so you’re essentially trying to tell root to use sudo which makes no sense.
In short, ‘with administrator privileges’ obviates the need to use sudo at all:
do shell script "/path/to/stunnel blah blah blah" with administrator privileges
To avoid the dialog prompting for the password:
do shell script "/path/to/stunnel blah blah blah" with administrator privileges password "itsabigsecret"
Thanks for the tip Camelot, I wasn’t aware of that.