Page 1 of 1

sudo shell script

PostPosted: Tue Jun 11, 2013 9:34 am
by sullivan
I'm trying to find a way to run the command: sudo chown admin on every new file added to a folder/subfolder on a server. Does anyone know how to get this to work by embedding the password in the shell/applescript?

Here's what I'm doing:
Hazel monitors for changed items in a folder/subfolders and invokes an applescript(processes the file into a path), which runs the shellscript on the file.

Any help would be greatly appreciated.

Re: sudo shell script

PostPosted: Tue Jun 11, 2013 11:50 am
by Mr_Noodle
Making the script setuid root will work but in general, I wouldn't recommend it as it is a security risk. That said, it's probably safer than having your password in cleartext.

Re: sudo shell script

PostPosted: Mon Jun 17, 2013 12:03 pm
by sullivan
I changed the sudoers file to get around the password issue but I'm getting a applescript error from hazel and can't figure out the problem.

2013-06-17 11:57:43.872 hazelworker[332] AppleScript error: { OSAScriptErrorNumberKey = "-1708";

here's the script:

set shell_script to "sudo chown admin "
tell application "Finder"
set the item_path to the quoted form of the POSIX path of theFile
do shell script (shell_script & item_path)
end tell

Re: sudo shell script

PostPosted: Mon Jun 17, 2013 12:18 pm
by sullivan
got it working, needed the handlers

Re: sudo shell script

PostPosted: Mon Oct 05, 2015 11:09 am
by seltzdesign
@sullivan

I need to the same thing. Can you tell me what you did to make it work. I'm not sure what you mean by
got it working, needed the handlers


Whatever I do I get that same OSAScript Error. Basically I need to watch a folder and do "sudo chown ..." and "chmod 775 " on everything as soon as it is added.

Doing "sudo chown .." with the embedded Shell Script option doesnt work. Doing the Apple Script thing with "do shell script (script) password "xxxx" with administrator privileges" should work, but somehow doesn't.

Thanks a lot for any hints on how to get this to work, it seems like you did!

Re: sudo shell script

PostPosted: Mon Oct 05, 2015 11:18 am
by seltzdesign
Ok, what do you know, as soon as I wrote the comment, tried again and its working.. :?

So now I have the problem that Hazel only runs the script in items on the top level, but not in subfolders. How did you get it to do that?

Re: sudo shell script

PostPosted: Mon Oct 05, 2015 2:01 pm
by Mr_Noodle
Read the sticky article on how to get Hazel to go into subfolders. That should do what you need.