logon logoff script

brizkallah
New Contributor II

hellow community, i need your help today with a DEALY issue after applying the following script in Jamf Pro. 

after adding the script into Jamf there is a delay with the logon for the end user.

username="$3"
serialnumber="$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" '/IOPlatformSerialNumber/{print $(NF-1)}')"
ip="$(ifconfig | grep 'inet 10' | grep -m1 -o '\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}' | grep -m1 '10')"

#echo ${username} >> /usr/local/bin/Logs/logs.txt
#echo ${serialnumber} >> /usr/local/bin/Logs/logs.txt
#echo ${ip} >> /usr/local/bin/Logs/logs.txt

1 REPLY 1

AJPinto
Honored Contributor II

Why are you trying to capture the SN, JAMF Assigned user name, IP, and user name at each log in? JAMF Already captures all this information from macOS's logs.

 

If you must do this, I would recommend making it a launchdaemon and cut JAMF out of it. Also >> will not create a directory, so if /usr/local/bin/logs does not exist it will error out. I would also replace $3 with a function to grab the logged in user from the Mac rather than JAMF.

 

Something like this may work better. Also do not use 777 as that is world writable, this is just for a simple example.

#!/bin/bash

username=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }' | tr "[a-z]" "[A-Z]"`
serialnumber="$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" '/IOPlatformSerialNumber/{print $(NF-1)}')"
ip="$(ifconfig | grep 'inet 10' | grep -m1 -o '\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}' | grep -m1 '10')"



if [ -d "/usr/local/bin/Logs" ]
then
	echo '/usr/local/bin/Logs/ Exists, writing log'
	sudo echo ${username} >> /usr/local/bin/Logs/logs.txt
	sudo echo ${serialnumber} >> /usr/local/bin/Logs/logs.txt
	sudo echo ${ip} >> /usr/local/bin/Logs/logs.txt
else
	echo '/usr/local/bin/Logs/ does not exist, creating directory'
	sudo mkdir "/usr/local/bin/Logs/"
	sudo chmod 777 "/usr/local/bin/Logs/"
	sudo echo ${username} >> /usr/local/bin/Logs/logs.txt
	sudo echo ${serialnumber} >> /usr/local/bin/Logs/logs.txt
	sudo echo ${ip} >> /usr/local/bin/Logs/logs.txt
fi