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:
- 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.
. - 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.
. - 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
Bookmarks