Book Image

Linux Command Line and Shell Scripting Techniques

By : Vedran Dakic, Jasmin Redzepagic
Book Image

Linux Command Line and Shell Scripting Techniques

By: Vedran Dakic, Jasmin Redzepagic

Overview of this book

Linux Command Line and Shell Scripting Techniques begins by taking you through the basics of the shell and command-line utilities. You’ll start by exploring shell commands for file, directory, service, package, and process management. Next, you’ll learn about networking - network, firewall and DNS client configuration, ssh, scp, rsync, and vsftpd, as well as some network troubleshooting tools. You’ll also focus on using the command line to find and manipulate text content, via commands such as cut, egrep, and sed. As you progress, you'll learn how to use shell scripting. You’ll understand the basics - input and output, along with various programming concepts such as loops, variables, arguments, functions, and arrays. Later, you’ll learn about shell script interaction and troubleshooting, before covering a wide range of examples of complete shell scripts, varying from network and firewall configuration, through to backup and concepts for creating live environments. This includes examples of performing scripted virtual machine installation and administration, LAMP (Linux, Apache, MySQL, PHP) stack provisioning and bulk user creation for testing environments. By the end of this Linux book, you’ll have gained the knowledge and confidence you need to use shell and command-line scripts.
Table of Contents (19 chapters)

Creating users and groups from a standardized input file and a random password for each user

In the previous recipe, we dealt with a way of creating new users. In this one, we are going to expand on this using a similar script to not only create new users but also assign them groups provided with the user, giving the administrator information on new user passwords.

Getting ready

We are creating users, so this script has to be run under an administrator account. In this particular case, we also probably want to redirect the output of the script to some file since passwords for new users are created when the script is run, and passwords are not stored anywhere. If we don't save them somewhere, they are going to be lost and recreated.

How to do it…

In the previous recipe, we mentioned that passwords should never be stored anywhere, but when creating new users, this is completely inevitable. We feel that the way we deal with passwords in this recipe is better...