Kaseya Community

Issues with Mac shell procedure, suspected to be with escape characters

This question is not answered

Hi there,

My company is seeing more and more macs so i am figuring out how to create procedures for them. Please forgive the awfulness of my grasp of bash script. This time I'm trying to script the creation of users- I can't seem to get the builtin Remote Control > Reset Password method to work fully. The danger is that OS X will allow you to create non-unique UniqueIDs.

In this instance I'm trying to find the highest UniqueID for users, which I can do easily enough in Terminal with this:
dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1

However my procedure sticks on the awk bit, which is the part that returns only the second column of data. It works as the logged-on user, whether that user is standard, admin or root, but it fails if I choose "execute as system". Root's user shell is also bash, and I've tested the command locally as su as well as sudo and it works, so it must be linked to Kaseya's "execute as system". I can work around it- but I'm going to be doing a lot more of this so I think I need to understand!

I've ruled out problems with the pipelining.

If I redirect the command's output to a file, then as it stands above I get an unfiltered file. That made me think that the ' were getting substituted with " so I tried escaping the ' with a second ' but this time I got an empty file. I've also tried using " instead of ', this resulted in no file at all being created.

I've tried escaping those ' with / and with \. I've tried wrapping various parts in brackets and wrapping various parts in different quotes. Too much to list. Does anyone have any suggestions?

All Replies
  • Check my desktop collector procedure. TONS of escaping. I think it will help to see how I handle escape characters with some pretty complex commands:


    I'm thrilled to see we have customers tarting to unleash the power of the command shell on OS X, so let me know if you're able to resolve your issue. I'll try to spend some time with your specific command myself if I get a chance.

  • Thanks Ben, I did check out your script before posting but didn't gain any insight. I ended up finding another way round.

    I posted my script here: