Skip to main content

I can't get any of my login hooks to work in Casper self service. I do
have other scripts that work



It seems anytime I use the ~ for logged in user it doesn't work.



Is this treated differently in Casper. I run it in terminal it works fine.
I am sure It is me doing something wrong



D. Trey Howell
trey.howell at austinisd.org
Desktop Engineering



Secret Windows code: while (1) { if (num_process > 1) {
bluescreen(rand()); } }

I thought they worked with self service too. You could test this out
with the following script.



#!/bin/bash



echo "$1" >> /tmp/variables.txt
echo "$2" >> /tmp/variables.txt
echo "$3" >> /tmp/variables.txt



Then you should be able to run it and see what the variables are.
Make sure you run it with casper to test it.



Ryan Harter
UW - Stevens Point
Workstation Developer
715.346.2716
Ryan.Harter at uwsp.edu


I just tested using Ryan's script, and sure enough, the $3 variable does not
work with logged in users (using Remote or Self Service). It appears that
variable only fills during login (or logout...I didn't test logout).



Steve Wood
Director of IT
swood at integerdallas.com



The Integer Group | 1999 Bryan St. | Ste. 1700 | Dallas, TX 75201
T 214.758.6813 | F 214.758.6901 | C 940.312.2475


Can you give examples of what you're trying to do?



Are you running them from policy? They are then executing as root not the current user I believe.



I'm working on some of the same stuff as well currently.



-Dusty-



Dustin Dorey



Technology Support Cluster Specialist



Independant School District 196



Rosemount-Apple Valley-Eagan Public Schools



dustin.dorey at district196.org



651|423|7971


The ~ expands as the current user's home directory. Login hooks, and
scripts in general in Casper, are run as root. That means that ~
would expand to root's home.



AFAIK it's general practice not to use the ~ in scripts because it's
not really interpreted the same everywhere. This probably isn't an
issue if you're only using them on Mac.



The way you would do this is to use the $3 variable, which Casper sets
to the username. Use something like /Users/$3/ to get the user's home
directory.



Ryan Harter
UW - Stevens Point
Workstation Developer
715.346.2716
Ryan.Harter at uwsp.edu


Just note that if you use the $3 variable it only runs as the current
user if Casper runs the script. If you run the script locally that
variable doesn't mean anything and if by some reason you need to run it
locally, you could loop through the /users and then execute your
commands.



Now I have successfully used the ~/ in scripts before, but I had to use
it as a variable and the script was intended to be ran by the user,
which was me. In general you don't want to use it.





Thomas Larkin
TIS Department
KCKPS USD500
tlarki at kckps.org
blackberry: 913-449-7589
office: 913-627-0351


SO just even trying a simple script like this it doesn't work



#!/bin/bash



mkdir ~/Desktop/testfolder



SO I tried what Ryan said and used $3 variable



mkdir /Users/$3/Desktop/testfolder



still couldn't get it to work???????



I am putting it in Self Service so I can test it. What I am doing is
trying to kill logged in users MCX settings and refresh. the script works
if ran by terminal.



D. Trey Howell
trey.howell at austinisd.org
Desktop Engineering



Secret Windows code: while (1) { if (num_process > 1) {
bluescreen(rand()); } }


Try



#!/bin/sh



cd /Users/$3/Desktop/



mkdir testfolder



I was just doing a similar test where I created a shell script threw it in casperadmin then executed it as a policy of once per user triggered by login. My test one was



#!/bin/sh



cd /Users/$3/Desktop/



rm Test.rtf



and that seemed to work fine. Ultimately I have some files that I need to change permissions to that are residing in our bound users library, but for testing purposes just to get used to the concept that’s what I did. The other guys on here have done WAY more with this than I have.



-Dusty-



Dustin Dorey



Technology Support Cluster Specialist



Independant School District 196



Rosemount-Apple Valley-Eagan Public Schools



dustin.dorey at district196.org



651|423|7971


Are you using default home directories? We are using ADmit Mac here
so our User directories are in /Domain/UWSP.EDU/Users/. I would say
you should also try hard coding the script, so maybe something like
this:



#!/bin/bash



mkdir /Users/testUser/Desktop/hardcodeTest



mkdir /Users/$3/Desktop/variableTest



Ryan Harter
UW - Stevens Point
Workstation Developer
715.346.2716
Ryan.Harter at uwsp.edu


If you go into your JSS under the Management Tab -> Management Preferences, what do you have checked for options under the Create Login/Logout Hooks section?



Are you seeing the policies triggered and attempting to run the script under /var/jamf.log?



Craig E


Craig,



I am just trying to get them to work in Self Service now, or even push
them out through Remote.



When I hard code it , it works. I just can't get it to reconize any
variables



I have used $1, $3, $home, ~



still no luck



D. Trey Howell
trey.howell at austinisd.org
Desktop Engineering
414-0102



Secret Windows code: while (1) { if (num_process > 1) {
bluescreen(rand()); } }


Forgive me if I am spreading bad information, but I was under the impression that scripts that called the logged on user only worked with login and logout policies and not anything else. Can someone tell me if that statement is wrong?



Craig E


OK guys, I think that $3 only works as a log in/out hook if the user is
already logged in I don't think it will work. I could be wrong, but
that is what I think.



Try something like this maybe?



#!/bin/sh



HOME=~/



mkdir $HOME/testdir





Thomas Larkin
TIS Department
KCKPS USD500
tlarki at kckps.org
blackberry: 913-449-7589
office: 913-627-0351


Another idea would be this, make sure you test it out



current_user=/usr/bin/finger -s -l | grep Login



mkdir /Users/$current_user/testdir



When I su to root in the shell and run finger it still picks up my
account as being logged in.





Thomas Larkin
TIS Department
KCKPS USD500
tlarki at kckps.org
blackberry: 913-449-7589
office: 913-627-0351


A few ways to get to the end results it seems. I've been using the following to get me a variable for $username



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



On 4/21/09 3:38 PM, "Thomas Larkin" <tlarki at kckps.org> wrote:



Another idea would be this, make sure you test it out



current_user=/usr/bin/finger -s -l | grep Login



mkdir /Users/$current_user/testdir



When I su to root in the shell and run finger it still picks up my
account as being logged in.





Thomas Larkin
TIS Department
KCKPS USD500
tlarki at kckps.org
blackberry: 913-449-7589
office: 913-627-0351


I think my solution would need to use awk, cut or sed, three commands I
am not that proficient with. Guess now is as good a time as any to
brush up! I don't think the grep is going to work.





Thomas Larkin
TIS Department
KCKPS USD500
tlarki at kckps.org
blackberry: 913-449-7589
office: 913-627-0351


HI



The following worked for me to output just the logged in name,



finger -s -l | grep Login | cut -c 8-25



When you run :



finger -s -l | grep Login



it gave me the following output :



Login: cmyers Name: Criss Myers



so therefore :



finger -s -l | grep Login | cut -c 8-25



gave me :



cmyers



but it might depend on the length of the name, but 17 characters should
be enough.



Criss



Criss Myers
Senior Customer Support Analyst (Mac Services)
Apple Certified Technical Coordinator v10.5
LIS Business Support Team
Library 301
University of Central Lancashire
Preston PR1 2HE
Ex 5054
01772 895054


I've used cut on /dev/console to get the current logged in user in a few of my scripts



user=ls -l /dev/console | cut -d " " -f 4



J



On 4/22/09 09:33 , "Thomas Larkin" <tlarki at kckps.org> wrote:



I think my solution would need to use awk, cut or sed, three commands I am not that proficient with. Guess now is as good a time as any to brush up! I don't think the grep is going to work.





Thomas Larkin
TIS Department
KCKPS USD500
tlarki at kckps.org
blackberry: 913-449-7589
office: 913-627-0351


Reply