Skip to main content
Question

Need to delete a symlink and replace it with a folder -or- how to un-dig a self-dug hole.

  • October 14, 2010
  • 4 replies
  • 21 views

Eyoung
Forum|alt.badge.img+10

I have ended up with an annoyance that seemed so easy to fix.. before I tried to fix it.

I have a random group of users with a symlink sitting in their home directory where the Movies folder used to be. I am trying to script my worries away but I've run into a roadblock thanks to the fact that all my users are networked.... so there's no local directory @ login.

Since my scritping kungfu is weak I am stuck. feel like this should be doable. Any advice?

seems so easy...

rm -r ~/Movies
mkdir ~/Movies
chmod 700 ~/Movies

If I could pass the command from root to the current console user that'd do it.

any clues would be of great help.

thanks

4 replies

Forum|alt.badge.img+11
  • Contributor
  • October 14, 2010

Hi,

Ive attached a script which you can put into Casper Admin, you can then use it to run any script as the logged in user,

Parameter 4 = the folder the script is in Parameter 5 = the script to run

or you could copy the following line to the script you want to use

#!/bin/sh

current_user=/usr/bin/w | grep console | awk '{print $1}'

echo $current_user

su $current_user pathtoscript/yourscript.sh

echo Done

exit 0

Criss

Criss Myers
Senior IT Analyst (Mac Services)
iPhone / iPad Developer
Apple Certified Technical Coordinator v10.5
LIS Development Team
Adelphi Building AB28
University of Central Lancashire
Preston PR1 2HE
Ex 5054
01772 895054


Eyoung
Forum|alt.badge.img+10
  • Author
  • Contributor
  • October 14, 2010

Excellent!! thank you for the leg up.

but... always a but... I am getting a error code I do not understand given the context of your script.

I put the script I want to run at /Library/Scripts/OITScripts, set as parameter 4, and the script name set as parameter 5. the script runs, but I get the following in the policy log:

Script Exit Code:0 Script Result: /private/tmp/RunCustomScript.sh: line 5: cd: HOME not set
Done

the script I refer to is as follows:

#!/bin/sh
rm -r ~/Movies
mkdir ~/Movies
chmod 700 ~/Movies


  • October 14, 2010

Try this?

#!/bin/bash

USER=who | grep "console" | cut -d" " -f1
rm ­r /Users/$USER/Movies
mkdir /Users/$USER/Movies
chown $USER:staff /Users/$USER/Movies
chmod 700 /Users/$USER/Movies

You should be able to run that from casper as a policy when a user is logged
in. So either a login hook or a self-service policy would probably be most
effective.

Bob


Eyoung
Forum|alt.badge.img+10
  • Author
  • Contributor
  • October 14, 2010

Along the lines of what I intended to do but as a network user there is nothing at /Users to act upon.

That's why I was working with ~/ instead of an absolute path. the benefits of network users is great but it makes the simple things inordinately frustrating at times.