PDA

View Full Version : Shell Script Running and Password Problems




skinicod
Jul 6, 2013, 06:08 PM
Hello All,

I have written the following script, which is intended to run at login:


mv /Library/"Application Support"/Digidesign/"Plug-Ins"/* /Library/"Application Support"/Digidesign/"Plug-Ins (Unused)"/

file=~/Desktop/"Plugins List.txt"
while IFS= read -r line
do
mv "/Library/Application Support/Digidesign/Plug-Ins (Unused)/$line" "/Library/Application Support/Digidesign/Plug-Ins/"
done <"$file"
mv "/Library/Application Support/Digidesign/Plug-Ins (Unused)"/XPand* "/Library/Application Support/Digidesign/Plug-Ins/"


The code runs fine except for certain files I get the following feedback:

mv: rename /Library/Application Support/Digidesign/Plug-Ins (Unused)/Wurlitzer V.dpm to /Library/Application Support/Digidesign/Plug-Ins/Wurlitzer V.dpm: Permission denied

I have changed the ownership of the shellscript to be root:admin, and added a line to my visudo:

# User privilege specification
root ALL=(ALL) ALL
%admin ALL=(ALL) ALL
OldBoyMusic ALL=(ALL) NOPASSWD:/plugin.sh

Any ideas why these files are not copying? if I log into terminal as a root user I can move them with no problems at all.

Secondly, does anyone know how I can get this script to run at login, I have tried setting up a plist in LaunchAgents, but this has not worked.

Thanks in advance for your responses,

cheers,

skinicod.



subsonix
Jul 7, 2013, 01:47 AM
Secondly, does anyone know how I can get this script to run at login, I have tried setting up a plist in LaunchAgents, but this has not worked.


The absolute easiest way is to use login items, you just need to add your script there. It's in system preferences under accounts.

Dalton63841
Jul 7, 2013, 01:51 AM
Found this to help automate sudo commands. Might be worth giving a shot.

if [ $UID -ne 0 ]; then
sudo $0
else

<SCRIPT GOES HERE>

fi

skinicod
Jul 7, 2013, 06:25 PM
Amazing, thank you both - exactly what I needed. In case anyone is interested I found this link (http://hints.macworld.com/article.php?story=20050517210406483) - which describes how to make a shellscript run in the background, by making it part of an AppleScript App.

Thanks again,

Skinicod.