Solved Scripting - How do you store your credentials and call them later?
-
@black3dynamite This, while it might work would be something else I have to install onto the target stations.
Not sure if I want to go down that route.
-
expect
on the otherhand is included on OSX by default, and might do it. -
What about something like this:
(taken from: https://superuser.com/questions/401906/how-to-pass-password-to-sudo-commands)
In your case it would be echo $PASSWORD | sudo -S -U $USER <command>
I just tested this on my Mac and it works.
-
@dafyre said in Scripting - How do you store your credentials and call them later?:
What about something like this:
(taken from: https://superuser.com/questions/401906/how-to-pass-password-to-sudo-commands)
In your case it would be echo $PASSWORD | sudo -S -U $USER <command>
I just tested this on my Mac and it works.
Maybe. . . it's not working with my naming computer script from yesterday.
-
When running
#!/bin/sh read -s -p "Enter a wheel username: " USER read -s -p "Enter a password for wheel: " PASS # Setting (office) offname variable read -p 'What office are you in?: ' offname # Setting (computer username variable) compuser variable read -p 'Enter this computers username (SAMAccountName) IE jdoe: ' compuser # Setting the asset tag (tagnumber) variable read -p 'Enter this computers asset tag: ' tagnumber echo $PASS | sudo -S -U $USER -l scutil --set HostName $offname$compuser && scutil --set ComputerName $compuser$tagnumber && scutil --set LocalHostName $offname$compuser$tagnumber
I'm met with
Enter a wheel user
Enter a password for wheel
what office are you in
enter this computers user. . .
enter this computers tag
And that I have to use
-l
with-U
(that is lower case L). -
sudo: the `-U' option may only be used with the `-l' option usage: sudo -h | -K | -k | -V usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user] usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command] usage: sudo [-AbEHknPS] [-C num] [-g group] [-h host] [-p prompt] [-u user] [VAR=value] [-i|-s] [<command>] usage: sudo -e [-AknS] [-C num] [-g group] [-h host] [-p prompt] [-u user] file ...
fun times. . ..
-
@DustinB3403 said in Scripting - How do you store your credentials and call them later?:
When running
#!/bin/sh
read -s -p "Enter a wheel username: " USER
read -s -p "Enter a password for wheel: " PASSSetting (office) offname variable
read -p 'What office are you in?: ' offname
Setting (computer username variable) compuser variable
read -p 'Enter this computers username (SAMAccountName) IE jdoe: ' compuser
Setting the asset tag (tagnumber) variable
read -p 'Enter this computers asset tag: ' tagnumber
echo $PASS | sudo -S -U $USER -l scutil --set HostName $offname$compuser && scutil --set ComputerName $compuser$tagnumber && scutil --set LocalHostName $offname$compuser$tagnumber
I'm met with
Enter a wheel user
Enter a password for wheel
what office are you in
enter this computers user. . .
enter this computers tag
And that I have to use
-l
with-U
(that is lower case L).Are you doing:
sudo myscript.sh
? Or are you just running the script and letting it call sudo?Also... What do you have to use
-U $USER?
-
This is the entire portion of the script I'm just testing with (so for the moment it is it's own script).
#!/bin/sh read -s -p "Enter a wheel username: " USER read -s -p "Enter a password for wheel: " PASS # Setting (office) offname variable read -p 'What office are you in?: ' offname # Setting (computer username variable) compuser variable read -p 'Enter this computers username (SAMAccountName) IE jdoe: ' compuser # Setting the asset tag (tagnumber) variable read -p 'Enter this computers asset tag: ' tagnumber echo $PASS | sudo -S -U $USER $PASS scutil --set HostName $offname$compuser && sudo -S -U $USER scutil --set ComputerName $compuser$tagnumber && sudo -S -U $USER scutil --set LocalHostName $offname$compuser$tagnumber
The script is run from a local wheel user so to run it, first I go
su wheel-user
(because our users by default aren't wheel users and thus need to jump to one) and then call that script. -
@dafyre said in Scripting - How do you store your credentials and call them later?:
@DustinB3403 said in Scripting - How do you store your credentials and call them later?:
When running
#!/bin/sh read -s -p "Enter a wheel username: " USER read -s -p "Enter a password for wheel: " PASS # Setting (office) offname variable read -p 'What office are you in?: ' offname # Setting (computer username variable) compuser variable read -p 'Enter this computers username (SAMAccountName) IE jdoe: ' compuser # Setting the asset tag (tagnumber) variable read -p 'Enter this computers asset tag: ' tagnumber echo $PASS | sudo -S -U $USER -l scutil --set HostName $offname$compuser && scutil --set ComputerName $compuser$tagnumber && scutil --set LocalHostName $offname$compuser$tagnumber
I'm met with
Enter a wheel user
Enter a password for wheel
what office are you in
enter this computers user. . .
enter this computers tag
And that I have to use
-l
with-U
(that is lower case L).Are you doing:
sudo myscript.sh
? Or are you just running the script and letting it call sudo?Also... What do you have to use
-U $USER?
running
su <wheel-user>
then./rename.sh
@dafyre said in Scripting - How do you store your credentials and call them later?:
Also... What do you have to use -U $USER?
what?
-
@DustinB3403 said in Scripting - How do you store your credentials and call them later?:
@dafyre said in Scripting - How do you store your credentials and call them later?:
@DustinB3403 said in Scripting - How do you store your credentials and call them later?:
When running
#!/bin/sh read -s -p "Enter a wheel username: " USER read -s -p "Enter a password for wheel: " PASS # Setting (office) offname variable read -p 'What office are you in?: ' offname # Setting (computer username variable) compuser variable read -p 'Enter this computers username (SAMAccountName) IE jdoe: ' compuser # Setting the asset tag (tagnumber) variable read -p 'Enter this computers asset tag: ' tagnumber echo $PASS | sudo -S -U $USER -l scutil --set HostName $offname$compuser && scutil --set ComputerName $compuser$tagnumber && scutil --set LocalHostName $offname$compuser$tagnumber
I'm met with
Enter a wheel user
Enter a password for wheel
what office are you in
enter this computers user. . .
enter this computers tag
And that I have to use
-l
with-U
(that is lower case L).Are you doing:
sudo myscript.sh
? Or are you just running the script and letting it call sudo?Also... What do you have to use
-U $USER?
running
su <wheel-user>
then./rename.sh
@dafyre said in Scripting - How do you store your credentials and call them later?:
Also... What do you have to use -U $USER?
what?
Sorry, Missed that... I meant to say WHY do you have to use -U $USER ?
sudo rename.sh doesn't work?
-
@dafyre said in Scripting - How do you store your credentials and call them later?:
Sorry, Missed that... I meant to say WHY do you have to use -U $USER ?
Because you need to elevate to root.
@dafyre said in Scripting - How do you store your credentials and call them later?:
sudo rename.sh doesn't work?
It does, but you are prompted to enter a username and password 3 times to make the edits. It's easy to fill-in but annoying to have to do repeatedly.
Hence my attempt at scripting the responses to the prompt windows (example below) Imagine having to type creds 3 times, for 100+ machines.
-
@dafyre said in Scripting - How do you store your credentials and call them later?:
@DustinB3403 said in Scripting - How do you store your credentials and call them later?:
@dafyre said in Scripting - How do you store your credentials and call them later?:
@DustinB3403 said in Scripting - How do you store your credentials and call them later?:
When running
#!/bin/sh read -s -p "Enter a wheel username: " USER read -s -p "Enter a password for wheel: " PASS # Setting (office) offname variable read -p 'What office are you in?: ' offname # Setting (computer username variable) compuser variable read -p 'Enter this computers username (SAMAccountName) IE jdoe: ' compuser # Setting the asset tag (tagnumber) variable read -p 'Enter this computers asset tag: ' tagnumber echo $PASS | sudo -S -U $USER -l scutil --set HostName $offname$compuser && scutil --set ComputerName $compuser$tagnumber && scutil --set LocalHostName $offname$compuser$tagnumber
I'm met with
Enter a wheel user
Enter a password for wheel
what office are you in
enter this computers user. . .
enter this computers tag
And that I have to use
-l
with-U
(that is lower case L).Are you doing:
sudo myscript.sh
? Or are you just running the script and letting it call sudo?Also... What do you have to use
-U $USER?
running
su <wheel-user>
then./rename.sh
@dafyre said in Scripting - How do you store your credentials and call them later?:
Also... What do you have to use -U $USER?
what?
Sorry, Missed that... I meant to say WHY do you have to use -U $USER ?
Also you said to do this, not I.
-
Woot got it!
-
Try this script...
#!/bin/sh # Setting (office) offname variable read -p 'What office are you in?: ' offname # Setting (computer username variable) compuser variable read -p 'Enter this computers username (SAMAccountName) IE jdoe: ' compuser # Setting the asset tag (tagnumber) variable read -p 'Enter this computers asset tag: ' tagnumber sudo scutil --set HostName $offname$compuser sudo scutil --set ComputerName $compuser$tagnumber sudo scutil --set LocalHostName $offname$compuser$tagnumber
Then just run the script with ...
sudo ./myscript.sh
You have to enter your password once at the beginning.
-
@DustinB3403 said in Scripting - How do you store your credentials and call them later?:
Woot got it!
Sweet! What did you wind up doing?
-
#!/bin/sh read -s -p "Enter a wheel username: " USER read -s -p "Enter a password for wheel: " PASS # Setting (office) offname variable read -p 'What office are you in?: ' offname # Setting (computer username variable) compuser variable read -p 'Enter this computers username (SAMAccountName) IE jdoe: ' compuser # Setting the asset tag (tagnumber) variable read -p 'Enter this computers asset tag: ' tagnumber echo $PASS | sudo -S scutil --set HostName $offname$compuser && sudo -S scutil --set ComputerName $compuser$tagnumber && sudo -S scutil --set LocalHostName $offname$compuser$tagnumber
-
@dafyre thanks for helping out there, it was almost there the sudo -S bit was all it needed, but for some odd flipping reason it recommends using -U flag as well which is weird.
But at least it works, now to fold this into the larger script and see how it all works.
-
@DustinB3403 said in Scripting - How do you store your credentials and call them later?:
@dafyre thanks for helping out there, it was almost there the sudo -S bit was all it needed, but for some odd flipping reason it recommends using -U flag as well which is weird.
But at least it works, now to fold this into the larger script and see how it all works.
I'll be over here in the corner with my hard hat on, watching for nuclear fallout, lol.
Glad you got it going!
-
@dafyre said in Scripting - How do you store your credentials and call them later?:
atching for nuclear fallout, lol.
I've already made a backup of the master script before edits.
-
I think my header really sells it.