Skip to main content
Solved

DEP Notify and Monterey 12.2+3 Python call

  • February 10, 2022
  • 12 replies
  • 19 views

I have been trying to sus out what is calling Python2(deprecated path) in my deployment workflow as we now get the JAMF Agent error that many others are seeing.  I have finally narrowed it down as to where it is...yet no idea how to correct it.  it looks like the script for calling/configuring DEP Notify that was supplied a while back has one single python call to get the current user:

# After the Apple Setup completed. Now safe to grab the current user. CURRENT_USER=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\\n");') echo "$(date "+%a %h %d %H:%M:%S"): Current user set to $CURRENT_USER." >> "$DEP_NOTIFY_DEBUG"

Does anyone have any recommendations as to how to correct/change this bit?  I've tried a few things and keep getting errors, yet this is a pretty complex script so I figured I would reach out.  

Best answer by karthikeyan_mac

 

CURRENT_USER=$(/usr/bin/stat -f "%Su" /dev/console)

 

 - This is used in DEPNotify Starter but there are many options.

 

CURRENT_USER=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
CURRENT_USER=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )

You can refer the below article by @arminBriegel where explains the difference of each method. Thank you @arminBriegel 

https://scriptingosx.com/2020/02/getting-the-current-user-in-macos-update/

12 replies

arnoldtaw
Forum|alt.badge.img+9
  • Contributor
  • 30 replies
  • February 10, 2022

  • 0 replies
  • February 10, 2022

@arnoldtaw ok so I didn't cut out the rest of the statement in the script like what you did there, I tried that exact statement prior to posting.  should I keep the echo statement below?  it should still work in theory.  I'll give it a whirl. Thank you


karthikeyan_mac
Forum|alt.badge.img+18
  • Honored Contributor
  • 284 replies
  • Answer
  • February 11, 2022

 

CURRENT_USER=$(/usr/bin/stat -f "%Su" /dev/console)

 

 - This is used in DEPNotify Starter but there are many options.

 

CURRENT_USER=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
CURRENT_USER=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )

You can refer the below article by @arminBriegel where explains the difference of each method. Thank you @arminBriegel 

https://scriptingosx.com/2020/02/getting-the-current-user-in-macos-update/


  • 0 replies
  • February 16, 2022

this was the full string that was tested:

#After the Apple Setup completed. Now safe to grab the current user. CURRENT_USER=$(/usr/bin/stat -f "%Su" /dev/console) echo "$(date "+%a %h %d %H:%M:%S"): Current user set to $CURRENT_USER." >> "$DEP_NOTIFY_DEBUG"

Works like a charm and eliminates any errors when running the workflow.


markdmatthews
Forum|alt.badge.img+17
  • Contributor
  • 67 replies
  • March 17, 2022

Also had good luck with curentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')


gmorgan
Forum|alt.badge.img+7
  • Contributor
  • 25 replies
  • May 6, 2022

If we're talking about the DEP script from JAMF from 2018 (v2.0.1), what line in the script is this?  I think I'm having the same issue and want to check it out.


gmorgan
Forum|alt.badge.img+7
  • Contributor
  • 25 replies
  • May 6, 2022

Nevermind.  I found it.  Lines 512-514.


  • 0 replies
  • May 6, 2022

Nevermind.  I found it.  Lines 512-514.


I was going to say somewhere near 500 - I ended up just searching for the python callouts with every script I had in the system using an editor so I could find them easier.  a number of replacements listed here will solve the issue vs re-tooling for v3.


Forum|alt.badge.img+1
  • New Contributor
  • 2 replies
  • July 5, 2022

Hey, 

First time poster here I am struggling with this currently. The way we were doing this in the past was a pop up with prompt the user to put name of computer, asset tag, Site and if student or staff device. This step fails now as a result of this error 

Our old code was this 

# After the Apple Setup completed. Now safe to grab the current user.
CURRENT_USER=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\\n");')
echo "$(date "+%a %h %d %H:%M:%S"): Current user set to $CURRENT_USER." >> "$DEP_NOTIFY_DEBUG"

 

tried a few of the above but the current one is this:

# After the Apple Setup completed. Now safe to grab the current user.
CURRENT_USER=$(/usr/bin/stat -f "%Su" /dev/console)
echo "$(date "+%a %h %d %H:%M:%S"): curentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')

 

I am getting this error:

Script result: /Library/Application Support/JAMF/tmp/DEPNotify Config Script - DEP: line 811: unexpected EOF while looking for matching `"'
/Library/Application Support/JAMF/tmp/DEPNotify Config Script - DEP: line 816: syntax error: unexpected end of file
Error running script: return code was 2.

 

I could use some help getting the functionality back. I worked with Jamf directly and was told to ask here also.

 

Thanks for any help you can provide! 


gmorgan
Forum|alt.badge.img+7
  • Contributor
  • 25 replies
  • July 5, 2022

You have errors in lines 811 and 816.  Missing parentheses or something. Not sure without knowing what line is which.  Here's ours:

# After the Apple Setup completed. Now safe to grab the current user and user ID
CURRENT_USER=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }')
CURRENT_USER_ID=$(id -u $CURRENT_USER)


Forum|alt.badge.img+1
  • New Contributor
  • 2 replies
  • July 5, 2022

You have errors in lines 811 and 816.  Missing parentheses or something. Not sure without knowing what line is which.  Here's ours:

# After the Apple Setup completed. Now safe to grab the current user and user ID
CURRENT_USER=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }')
CURRENT_USER_ID=$(id -u $CURRENT_USER)


That did the trick! replace the lines of code and its working again. Thanks!

I don't know why there were errors in line 811 but they went away. So no issues there.

Thanks again!


gmorgan
Forum|alt.badge.img+7
  • Contributor
  • 25 replies
  • July 5, 2022

That did the trick! replace the lines of code and its working again. Thanks!

I don't know why there were errors in line 811 but they went away. So no issues there.

Thanks again!


Great! Enjoy.