← Back Published on

Improving Command-Line Productivity

This lab was performed on a workstation machine to create a script file named bash-lab in the /home/student/bin directory. The script file was created using the vim command, made executable using the chmod command, and edited to comply with the requested information from the servera and serverb hosts. The required information was saved to the output-servera and output-serverb files in the /home/student directory on the workstation.

Outcome

The objective of this lab was to create a Bash script file that would run commands on two remote servers, servera and serverb, via SSH and save the output to two different files named output-servera and output-serverb, respectively. The saved files were expected to contain specific pieces of information requested in the lab exercise.

Tasks

Create the /home/student/bin directory and 
reate and edit the /home/student/bin/bash-lab script file using the following command:

Insert the following text to the /home/student/bin/bash-lab script file:

#!/usr/bin/bash

Make the script file executable using the following command:

Edit the newly created script file to comply with the requested information from servera and serverb hosts. The systems use SSH keys for authentication, and therefore no password is required. The following information was requested:

Command or fileContent requested
hostname -fGet all the output.
echo "#####"Get all the output.
lscpuGet only the lines that start with the string CPU.
echo "#####"Get all the output.
/etc/selinux/configIgnore empty lines. Ignore lines starting with #.
echo "#####"Get all the output.
/var/log/secureGet all "Failed password" entries.
echo "#####"Get all the output.

Using the vim command, append the bash-lab script

Execute the /home/student/bin/bash-lab script, and review the output content on workstation. Using two commands we can see the output. The

The output of both commands also includes some logs from the sshd service on each server. Specifically, it shows failed attempts to log in with invalid usernames from a specific IP address and port number. The logs suggest that someone (or something) is attempting to brute force their way into the servers by trying various usernames and passwords.

Conclusion

This lab exercise focused on creating a Bash script that would execute various commands on two remote hosts, servera and serverb, via SSH. The script was created and edited using the vim command, with the initial content being the shebang interpreter directive. The script was made executable using the chmod command. The script executed commands to retrieve the hostname, CPU information, SELinux configuration, and failed password entries from the /var/log/secure file. The output was saved to separate files for each server in the /home/student/output directory. The script was executed successfully, and the output files were reviewed to ensure that the required information was obtained. Overall, this lab exercise helped to develop skills in Bash scripting and using SSH to execute commands on remote hosts.