Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Lew4484

macrumors newbie
Original poster
Mar 23, 2011
5
0
Hi all, I am trying to produce a login script that will basically create a folder at startup, set it's permissions and also move a set of files to the users preferences folder when logging in with a network account (workgroup manager won't allow me to do this and the files are greyed out). I have also set a logouthook to delete the folder when then log out (it's to be used as a scratch disk). I find that the login script works fine when I run it manually as a network user, but when I set a loginhook, parts of the script work and it will create a folder and set it's permissions, but it will not copy the files over to the user preferences folder. After a bit of research I found that this may be because it is running as a root user and this will ignore paths such as ~/library/ (I'm a beginner in regards to shell scripts and programming, so please correct me if this is wrong). Does anybody know a more effective way to get this to work?

Here is a copy of the script if you need it:

#!/bin/sh

mkdir "/Scratch/Scratch"
chmod a+w /Scratch/Scratch
cp -r /Library/Preferences/FinalCut/* ~/Library/Preferences


The files being copied over are to basically set the scratch disk location in Final Cut to the temporary folder created at startup. The entire process is as follows,

  • Create folder in /Scratch called Scratch at startup to be used as a scratch disk
  • Set permissions to 'read and write' for all users
  • Move a set of files located in /Library/Preferences/FinalCut to the users preferences folder
  • Delete the scratch disk on log out

If anyone sees a better way of achieving what I'm trying to do please let me know.
 
Well according to this Apple Knowledge Base article, you are right that a login hook is executed as root. The article also states that the variable $1 returns the short name of the user who is logging in. So if you change the destination of the cp command this should work I would think....

Code:
#!/bin/sh

 mkdir "/Scratch/Scratch"
 chmod a+w /Scratch/Scratch
 cp -r /Library/Preferences/FinalCut/* /Users/"$1"/Library/Preferences
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.