Mac Script Problems

Joined
Jan 21, 2012
Messages
3
Reaction score
0
Points
1
Okay. I will say that I came from another forum searching for help, as no one there really knows anything about Mac scripts, but seem to know everything else about FreeBSD, Linux, and of course Windows.

I know many languages including those like C++ and Java, and I know a bit about the Mac syntax and a couple of it's commands, but I am stumbling when it comes to this script as I have never written a shell script for mac.

Can someone please help me and tell me what I am doing wrong?

Code:
#!/bin/bash
echo Enter Username:
read user
sudo dscl localhost -read /Search/Users/$user | grep GeneratedUID | cut -c15-
echo Copy above line for GUID:
read guid
sudo cat /var/db/shadow/hash/$guid | cut -c169-216
echo Above is the mac hash...

Any help is appreciated.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
I'm not sure why the *nix people couldn't help since you're writing a bash script. Anyway...

You'll have to be a little more specific. What about the above isn't working? What are you trying to accomplish and what are you getting when you run this?
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
/var/db/shadow/ <-- for starters does this directory exist? It doesn't on my Mac.

I also generally don't like $user, it's too close to an already defined system variable.

Additionally, I'd personally do something like :
Code:
i=sudo dscl localhost -read /Search/Users/mike | grep GeneratedUID | cut -c15-

cat $i
Instead of making the user copy/paste
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Instead of $user, you could use the following (that's not a typo - there's no slash between /Search and $HOME since $HOME contains the slash):
Code:
/Search$HOME
Like Dys, also I don't have /var/db/shadow nor do I have /Search.
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
yea, but you will get results from

sudo dscl localhost -read /Search/Users/$USER

;)

Oh and other than that.. No, I will not help you parse out and decrypt a password.
 
OP
X
Joined
Jan 21, 2012
Messages
3
Reaction score
0
Points
1
Well, I don't care about that, I know how to do it. I was just looking for a faster way...
But okay...
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Can someone please help me and tell me what I am doing wrong?

Well, I don't care about that, I know how to do it. I was just looking for a faster way...
But okay...
Is there something wrong or do you want a quicker way? Care to explain what it is that you're trying to accomplish? Knowing this will help make this a quicker process.
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
Well, I don't care about that, I know how to do it. I was just looking for a faster way...
But okay...

If you knew how to do it, scripting it would be a simple matter of passing the same commands. Without knowing what the failing point is, it's impossible to tell you what you're doing wrong. Although, since you're running sudo commands, you're not in an environment where you can access what you want to.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top