[Casper] Script Help: Logged On user
Ryan Harter
rharter at uwsp.edu
Fri Sep 26 12:47:51 PDT 2008
Hey Craig-
I know you've said you have this working, but I just thought I'd throw
in my two cents.
I have seen some issues with using last depending on when the script
is run. I don't mean 'when' as in 'at login,' but more precise than
that. We have found that sometimes the script will run before last
has been updated and that is why the $3 fix in Casper is so imperative.
As for the $1 that you read online. $1 is really just the first
parameter, whatever that might be. So if you run the script with the
command "/bin/sh /some/local/script.sh" and print $1 it will be null.
You need to run it like you would any other command line app. What I
would suggest, is modify the Policy that fires it off to have the lines:
USER=$3 #pull the username from casper
/path/to/script.sh $USER #you could potentially pass any other
parameters you need as well.
Then the username will be accessible from script.sh as $1.
The thing to keep in mind is that the list of parameters (actually
it's everything in the command that fires off a script, eg. <script>
<param1> <param2> etc.) is really just a zero based array from within
that script. So if you fire off a script by running:
/path/to/script.sh param1 param2 param3
Then to access all of that you could
/bin/echo "$0" # returns /path/to/script.sh
/bin/echo "$1" # returns param1
/bin/echo "$2" # returns param2
/bin/echo "$3" # returns param3
Forgive me if this is elementary stuff. I do a lot of scripting here
at UWSP and I feel it's an invaluable skill.
Ryan Harter
UW - Stevens Point
Workstation Developer
715.346.2716
Ryan.Harter at uwsp.edu
On Sep 26, 2008, at 1:40 PM, Ernst, Craig S. wrote:
> I don’t want it for every user though, just a particular group of AD
> users that will be doing laptop check-ins etc for a laptop pool. And
> this way I can change out the groups, or individuals easily within
> the scope of the policy. =)
>
> It’s ok. Nick from JAMF helped me out a little here with two
> different versions. Could have just used $3 if the script was being
> run directly from Casper stuffs, which I already knew wouldn’t work.
>
> username=`/usr/bin/w | grep console | awk ‘{print $1}’`
>
> OR
>
> username=`/usr/bin/last –1 | grep awk ‘{print $1}’`
>
> However, I had to make sure that the command in the advanced tab of
> the JSS policy was backgrounded otherwise the login never completes
> fully until AFTER the script was running. So I had to have the
> command in the JSS ‘/bin/sh /some/file/ondisk.sh &’.
>
> Thanks all!
>
> Craig E
>
>
> On 9/26/08 1:25 PM, "Thomas Larkin" <tlarki at kckps.org> wrote:
>
>
>
> If the script is already on the local machine why not make a lauchd
> item under /Library/LaunchAgents which will trigger at log in for
> each user and then just wild card the script out to copy to each
> user in /Users?
>
>
>
>
>
>
> ___________________________
> Thomas Larkin
> TIS Department
> KCKPS USD500
> tlarki at kckps.org
> blackberry: 913-449-7589
> office: 913-627-0351
>
>
>
>
>
> >>> "Ernst, Craig S." <ERNSTCS at uwec.edu> 09/26/08 1:07 PM >>>
>
>
>
>
> I tried $1 earlier because that was everything I had ready online,
> but that came back with nothing, at least in Leopard. =)
>
> Craig
>
>
> On 9/26/08 9:56 AM, "Miles Leacy IV" <miles.leacy at gmail.com> wrote:
>
>
>
>
>
>
>
> I don't have my script library with me, but I believe in a bash login
> script, $1 returns the short name of the user logging in. It might be
> $2 or $3. I really ought to put my scripts on my iDisk. :)
>
>
> On Fri, Sep 26, 2008 at 10:37 AM, Ernst, Craig S. <ERNSTCS at uwec.edu>
> wrote:
> > This is the dumbest thing, but I need some help with some
> scripting if
> > possible.
> >
> > I have a policy that calls a shell script that's already local on
> the box
> > (why it has to be local I won't get into here) when a particular
> set of
> > users logs on as defined in the policy. So the advanced tab has a
> command
> > for '/bin/sh /some/file/ondisk.sh'
> >
> > What I need it to do is copy a file also local on the machine to
> the Desktop
> > of the user that just logged on. I can't just use username=$
> (whoami) because
> > the policy calls the script as root, and it shouldn't copy to root
> of
> > course.
> >
> > Can someone help? Let me know if you need more clarification. I'm
> sure this
> > should be the simplest thing ever for me to do, but for the life
> of me...
> >
> > Thanks,
> >
> > Craig Ernst
> > Systems Management & Configuration
> > ----------------------------------
> > University of Wisconsin-Eau Claire
> > Learning & Technology Services
> > 105 Garfield Ave
> > Eau Claire, WI 54701
> > Phone: (715) 836-3639
> > Fax: (715) 836-6001
> > ----------------------------------
> > ernstcs at uwec.edu
> >
> > _______________________________________________
> > Casper mailing list
> > Casper at list.jamfsoftware.com
> > http://list.jamfsoftware.com/mailman/listinfo/casper
> >
>
>
>
>
>
> <ATT00001.txt>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.jamfsoftware.com/pipermail/casper/attachments/20080926/c2bf60c1/attachment.html
More information about the Casper
mailing list