Results 1 to 2 of 2

Thread: [Help] User input prompts & automated scripting

  1. #1
    Join Date
    Nov 2011
    Beans
    32

    [Help] User input prompts & automated scripting

    Hello,

    I'm trying to write a simple bash script that can automate creating users and logging them in, or for any general purpose use where a command is run and a prompt shows up asking for user input (such as "username: ", "password: ", "continue? [y/n]", "press enter to continue", etc...)

    Here's a few things:


    1. I already know that entering a password using a command in the terminal or by using a script is bad practice because you can use the ps command to see it. For my purposes, this won't matter.
      .
    2. I do not want to enable "autologon" to Ubuntu to automatically log me in when I start it up. This is not the solution I need.
      .
    3. I tried looking up the "expect" command and creating an expect script, but was confused by it, and if possible, I'd like to only have one script that contians all of the information I need (the commands, the username, the password, etc..). I know that it is bad practice to do this.


    Here are some things I Google'd but they failed:

    Code:
    (in terminal window or script)
    
    echo "password" | login username
    
    (acts if nothing happened)
    Code:
    (in terminal window or script)
    
    login username && echo "password"
    
    (runs first command, waits until first command is finished, then runs second command)
    Code:
    (in terminal window or script)
    
    login username & echo "password"
    
    (runs both at same time, usually "echo" first, but does not enter "password" into the first command)
    Code:
    (in .sh file)
    
    #!/bin/bash
    
    login username
    expect "*?assword:*"
    send -- "$password\r"
    
    (errored with: send: command not found)
    and different variations of these.

    This is what I want to happen (doesn't have to be used with root account):

    Code:
    root@ubuntu:~# adduser USER
    Adding user `USER' ...
    Adding new group `USER' (1006) ...
    Adding new user `USER' (1004) with group `USER' ...
    Creating home directory `/home/USER' ...
    Copying files from `/etc/skel' ...
    Enter new UNIX password:  [autofill]
    Retype new UNIX password:  [autofill]
    passwd: password updated successfully
    Changing the user information for to
    Enter the new value, or press ENTER for the default
        Full Name []:  [Enter key pressed or autofill]
        Room Number []: [Enter key pressed or autofill]
        Work Phone []: [Enter key pressed or autofill]
        Home Phone []: [Enter key pressed or autofill]
        Other []: [Enter key pressed or autofill]
    Is the information correct? [Y/n] [Y or n pressed or Enter key pressed]
    If possible, I'd like it to be verbose like the code above. If that can't happen, it's not a big deal.

    Thanks,

    -- Ben

  2. #2
    Join Date
    Mar 2011
    Location
    U.K.
    Beans
    Hidden!
    Distro
    Ubuntu 22.04 Jammy Jellyfish

    Re: [Help] User input prompts & automated scripting

    I would try using an automation script created in Actionaz GUI. Actionaz package is in repo.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •