πŸ“ŒShell Scripting

  1. It is a set of commands written in an executable file to automate any task. The commands are converted then to machine-readable form to execute.

  • Syntax:-

    #!/bin/bash

    <commands>

  1. The file to be created must be with extension ".sh" and provided with necessary execute permissions to the user running the script.

  2. Navigate to the server and create a directory of your suitable name.

  3. Create a shell script file. I have created here a AWS_resource.sh file.

  4. In this project, I have chosen few resources to display and they are:-

  • AWS EC2

  • S3 Buckets

  • AWS Lambda

  • IAM users

  1. The shell script file determine the AWS resource usage is as below:-

#!/bin/bash

path=/home/ubuntu/shell_script/script.sh

############################AWS Active Resources ####################################################################### echo "-----------------------------------------------------------------------------------------------------------------------------------------------------" 
#List S3 buckets
 echo "list aws s3 buckets:" 
aws s3 ls 
echo "-----------------------------------------------------------------------------------------------------------------------------------------------------" 
#list EC2 instances 
echo "list ec2 instances:" 
aws ec2 describe-instances 
echo "-----------------------------------------------------------------------------------------------------------------------------------------------------" 
#list lambda 
echo "list ec2 lambda:" 
aws lambda list-functions 
echo "-----------------------------------------------------------------------------------------------------------------------------------------------------" 
#list IAM users 
echo "list IAM users:" 
aws iam list-users
  1. Now, let's add the server health monitoring where we have determined disk space and memory of the server.

  1. Save the file and now give permission to the file with below command.

  1. In this project we will send the mail to the user's account for which E-Mail services needs to be setup which we will see in next section.

  2. We need to put the output to a text file and then send the file content to the Email address. The shell script for this cause is:-

Last updated