Help with a script

JZaczyk
New Contributor

So we're trying to set things up to use Google Drive as an automagic backup solution here. I've used MacDropAny to set up my proof of concept, but I feel like that'll be too time consuming to set up on all our users' machines. I'm trying to write a script and deploy it via self service once the user's account is created, Google Drive is installed, and signed in. I've got the commands down to move the contents of the Home folder to Google Drive, then create symlinks back in the Home folder, but I'm having trouble getting it to run as local admin, as there's a few sudo's in the script and the account I'd be running it from would not have admin rights. I'm leaning towards ssh-ing into admin@localhost to get admin rights, but am stumbling on feeding the password to the script. Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

ShaunRMiller83
Contributor III

How are you planning to run your script? If you are running the script using a LaunchDaemon you could have it run as root or run for all users so that shouldn't be an issue. Alternatively you could setup a Casper policy and set it to make available for offline use. Which would functionally be similar.

Also note if you decide to run it thru Casper since the script would run as root technically you won't need the sudo commands since you're already root. Depending on your security & logging that may be a concern or maybe not.

I should have added to my initial post if you do go the LaunchDaemon route you may want to check out Lingon X.

View solution in original post

3 REPLIES 3

ShaunRMiller83
Contributor III

How are you planning to run your script? If you are running the script using a LaunchDaemon you could have it run as root or run for all users so that shouldn't be an issue. Alternatively you could setup a Casper policy and set it to make available for offline use. Which would functionally be similar.

Also note if you decide to run it thru Casper since the script would run as root technically you won't need the sudo commands since you're already root. Depending on your security & logging that may be a concern or maybe not.

I should have added to my initial post if you do go the LaunchDaemon route you may want to check out Lingon X.

brad
Contributor

Like @ShaunM9483 said, run the script from Casper or as a LaunchDaemon and it will run with root privileges. If you need the script to execute a portion as the user you can use:

sudo -u <username> -i 'command arguments'

So,

sudo -u brad -i 'whoami'

Returns: brad

or:

sudo -u brad -i 'cd ~/Desktop;pwd'

Returns /Users/brad/Desktop

Happy backing up and scripting!
-Brad

JZaczyk
New Contributor

Thanks for the help! I was totally overthinking it and just trying to execute the script on my test case rather than deploying via Casper.