ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Solved Scripting - How do you store your credentials and call them later?

    IT Discussion
    shell script credentials hashing
    7
    79
    5.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DustinB3403D
      DustinB3403 @dafyre
      last edited by

      @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.

      R4YZS0B19iFjV9eMoQ5WRzipOS6IVXMy.png

      1 Reply Last reply Reply Quote 0
      • DustinB3403D
        DustinB3403 @dafyre
        last edited by

        @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.

        1 Reply Last reply Reply Quote 0
        • DustinB3403D
          DustinB3403
          last edited by

          Woot got it!

          dafyreD 1 Reply Last reply Reply Quote 0
          • dafyreD
            dafyre
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • dafyreD
              dafyre @DustinB3403
              last edited by

              @DustinB3403 said in Scripting - How do you store your credentials and call them later?:

              Woot got it!

              Sweet! What did you wind up doing?

              1 Reply Last reply Reply Quote 0
              • DustinB3403D
                DustinB3403
                last edited by

                #!/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
                
                1 Reply Last reply Reply Quote 3
                • DustinB3403D
                  DustinB3403
                  last edited by

                  @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.

                  dafyreD 1 Reply Last reply Reply Quote 2
                  • dafyreD
                    dafyre @DustinB3403
                    last edited by

                    @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!

                    DustinB3403D 1 Reply Last reply Reply Quote 0
                    • DustinB3403D
                      DustinB3403 @dafyre
                      last edited by

                      @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.

                      1 Reply Last reply Reply Quote 1
                      • DustinB3403D
                        DustinB3403
                        last edited by

                        I think my header really sells it.

                        powershell_wJLd1e1YLE.png

                        1 Reply Last reply Reply Quote 2
                        • DustinB3403D
                          DustinB3403
                          last edited by

                          I'm of course just kidding, lord knows I'd actually get dragged to court with a disclaimer like this. . .

                          Time to find the GNU license and insert that. . .

                          1 Reply Last reply Reply Quote 1
                          • IRJI
                            IRJ
                            last edited by

                            I'm glad you found a solution, but have you considered ansible for tasks like this?

                            DustinB3403D 1 Reply Last reply Reply Quote 0
                            • DustinB3403D
                              DustinB3403 @IRJ
                              last edited by

                              @IRJ said in Scripting - How do you store your credentials and call them later?:

                              I'm glad you found a solution, but have you considered ansible for tasks like this?

                              Have you consider our lord and savor jesus christ?

                              FFS man...

                              Of course I have I just don't understand it as all of their documentation is god awful and I'd have to take numerous pounds of coke up the backdoor to understand what the hell I'm supposed to do.

                              On a positive note, if you want to jump on a skype call some time or another I'd be happy to learn if you're willing to teach.

                              stacksofplatesS IRJI 2 Replies Last reply Reply Quote 0
                              • stacksofplatesS
                                stacksofplates @DustinB3403
                                last edited by

                                @DustinB3403 said in Scripting - How do you store your credentials and call them later?:

                                @IRJ said in Scripting - How do you store your credentials and call them later?:

                                I'm glad you found a solution, but have you considered ansible for tasks like this?

                                Have you consider our lord and savor jesus christ?

                                FFS man...

                                Of course I have I just don't understand it as all of their documentation is god awful and I'd have to take numerous pounds of coke up the backdoor to understand what the hell I'm supposed to do.

                                I don't know what you're on. It's some of the better documentation. I'd be interested to see what specific parts you are referencing.

                                DustinB3403D 1 Reply Last reply Reply Quote 0
                                • DustinB3403D
                                  DustinB3403 @stacksofplates
                                  last edited by

                                  @stacksofplates 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?:

                                  @IRJ said in Scripting - How do you store your credentials and call them later?:

                                  I'm glad you found a solution, but have you considered ansible for tasks like this?

                                  Have you consider our lord and savor jesus christ?

                                  FFS man...

                                  Of course I have I just don't understand it as all of their documentation is god awful and I'd have to take numerous pounds of coke up the backdoor to understand what the hell I'm supposed to do.

                                  I don't know what you're on. It's some of the better documentation. I'd be interested to see what specific parts you are referencing.

                                  Specifically using it to administrator Apple OSX laptops and workstations is what I'm particularly interested in. We have very few linux systems here that would require automation on any scale.

                                  1 Reply Last reply Reply Quote 0
                                  • DustinB3403D
                                    DustinB3403
                                    last edited by

                                    Like 85-90% of this office is OSX, so anything to help reduce that overhead would be great. I've even posted here about looking at all of these automation tools and which was best and it turned into a this one is cool, but it doesn't do that one thing you absolutely need.

                                    1 Reply Last reply Reply Quote 0
                                    • DustinB3403D
                                      DustinB3403
                                      last edited by

                                      PS I learn from seeing and doing, rather than reading. Just as an FYI.

                                      ObsolesceO 1 Reply Last reply Reply Quote 0
                                      • DustinB3403D
                                        DustinB3403
                                        last edited by

                                        And the peanut gallery falls silent.

                                        1 Reply Last reply Reply Quote 0
                                        • stacksofplatesS
                                          stacksofplates
                                          last edited by stacksofplates

                                          So I admittedly don't know anything about Macs because I don't care to, but here is a simple way to do this with Ansible.

                                          ---
                                          - name: Set crap with scutil
                                            hosts: macs
                                            become: true
                                            user: dustin
                                            vars:
                                              -computername: "this_computer_sucks"
                                          
                                            tasks:
                                              - name: set computername
                                                shell: "scutil --set ComputerName {{ computername }}"
                                          
                                              - name: set hostname
                                                shell: "scutil --set HostName {{ computername }}"
                                          
                                              - name: set localhostname
                                                shell: "scutil --set LocalHostName {{ computername }}"
                                          

                                          If spacing is off, I'm on my phone so suck it up.

                                          IRJI 1 Reply Last reply Reply Quote 2
                                          • DustinB3403D
                                            DustinB3403
                                            last edited by

                                            @stacksofplates so that seems simple enough, how do you put in the custom details like I am pushing to these 1 by 1?

                                            the office location, the expected user and the asset tag to create a single -computername ?

                                            Also since we're on it, how do you use tools like brew.sh to install and update third party software?

                                            IRJI stacksofplatesS 3 Replies Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 2 / 4
                                            • First post
                                              Last post