Skip to content

Personally Developed Prod Scripts and Project-Based Shell Scripts

Notifications You must be signed in to change notification settings

Codehunter-py/Shell-scripting

Repository files navigation

Shell-scripting

Includes personally developed Production and Project-Based Shell Scripts

Technologies and Tools

Description:
The purpose of this repository files is to run shell scripts in a local Linux lab environment and test them before deploying the prod environment. Once you have the environment configured you can quickly and easily create and destroy Linux virtual machines on your Windows, Mac, or Linux computer.

Use case of Scripts

  • Add users to a Linux system
  • All basics in the process
  • Text and data manipluation through pipes
  • Handling command line arguments
  • Using special positional parameters
  • Generating random Passwords
  • Using for and while loops
  • Mastering I/O
  • Linux programming conventions
  • Automation of monthly updates
  • Create/Update operational scripts

How to run

Install an SSH Client (Windows Users Only)
SSH, secure shell, is the network protocol used to connect to Linux systems. By default Windows doesn’t include an SSH client. Mac and Linux do, so Mac and Linux users should skip this step. In order to get an SSH client on Windows you can install Git. Git is used for version control, but we’re interested in the SSH client that it ships with. Download git here: https://git-scm.com/download/win
Start the installer. Be sure to select "Use Git and optional Unix tools from The Windows Command Prompt" when presented with the option. Otherwise, use the defaults. If you're asked for an administrator user and password, be sure to enter it.

Install VirtualBox (All Users)
Download VirtualBox from https://www.virtualbox.org/wiki/Downloads. If you are using Windows, download the file from the windows subdirectory. If you are using a Mac, download the file from the mac subdirectory. If you are using RedHat or Centos, download the file from the centos directory.

Install Vagrant (All Users)
Download Vagrant from https://www.vagrantup.com/downloads.html If you are using Windows, download the file from the windows subdirectory. If you are using a Mac, download the file from the mac subdirectory. If you are using RedHat or CentOS, download the file from the centos directory.
Install the software on your local machine, accepting all the defaults. If you're asked for an administrator user and password, be sure to enter it. Reboot your system if requested by the installer.

Start a Command Line Session (All Users)

First, start a command line session on your local machine. For Windows users, start the Command Prompt. (Click the Start button. In the Search box, type "Command Prompt", and then, in the list of results, double-click Command Prompt.) For Mac users, start the Terminal application which is located in the /Applications/Utilities folder.
For Linux users, start your favorite terminal emulator. Examples include GNOME Terminal, Konsole, and xterm.
Add a Box to Vagrant
A "box" in Vagrant speak is an operating system image. The "vagrant box add " command will download and store that box on your local system. You only need to download a box once as this image will be cloned when you create a new virtual machine with Vagrant using the box’s name. I created a box specifically for this class and uploaded it to the public Vagrant box catalog. Run the following command on your local machine to download it.
vagrant box add jasonc/centos7
The format of the command when downloading a public box is "vagrant box add USER/BOX". There are several public boxes available to download. You can search for boxes here, but be sure to use the "jasonc/centos7" box for this class. https://app.vagrantup.com/boxes/search

Create a Working Folder

When the Command Prompt (Windows) or the Terminal (Mac/Linux) is launched you will be placed in your home directory. For example, if I’m logged into a Windows system as "user" my home directory could be "C:⧵Users⧵user". (Note: this might vary depending on the version of Windows you are using.) If I’m logged into a Mac system as "user" my home directory will be "/Users/user". If I'm logged into a Linux system as "user" my home directory will be "/home/user".
Create a folder to keep your course work in.
mkdir shell-scripting
Change into the Working Folder Now let's move into the folder we just created.
cd shell-scripting
Create a Vagrant Project Folder
Vagrant uses the concept of projects. A Vagrant project must consist of a folder and a Vagrant configuration file, called a Vagrantfile. Start out by creating a "testbox01" folder.
mkdir testbox01
Create Your First Vagrant Files
To create the Vagrant configuration file (Vagrantfile), run the "vagrant init <BOX_NAME> " command. Be sure to be in Vagrant project directory you just created. Also, use the "generic/rhel8" box you downloaded earlier.
cd testbox01
vagrant init generic/rhel8

Create Your First Virtual Machine

The first time you run the "vagrant up " command Vagrant will import (clone) the vagrant box into VirtualBox and start it. If Vagrant detects that the virtual machine already exists in VirtualBox it will simply start it. By default, when the virtual machine is started, it is started in headless mode meaning there is no UI for the machine visible on your local host machine.
Bring up your first virtual machine running Linux with Vagrant.
vagrant up

Now it is ready to test scripts

Once all installments and configurations are done, you can download repository files and copy them to the Vagrant Project folder. For example:
cd shell-scripting/testbox01
vagrant up
./file-name

About

Personally Developed Prod Scripts and Project-Based Shell Scripts

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published