Skip to main content

Command Palette

Search for a command to run...

Shell Scripting Project

Updated
1 min read
Shell Scripting Project
V

Hello! I'm a student passionate about becoming a Cloud and DevOps Engineer. I have a solid foundation in AWS Cloud, Linux, Docker, and Kubernetes.

1. Report the Usage of AWS Resources using Shell Scripting

For Reporting the usage of AWS resources let's write a script.

  1. create a file aws_resourceses_report.sh and write script.

  2.  #!/bin/bash
    
     #############################
     #Author: Vishal
     #Date: 23-06-2024
     #Version: v1
     #this script will report aws resource usage
     #############################
     #AWS S3
     #AWS EC2
     #AWS IAM
    
     set -x 
     set -e 
     set -o pipefail
    
     #List S3 buckets
     aws s3 ls
    
     #List EC2 instance Id
     aws ec2 describe-instances | jq '.Reservations[].Instances[].InstanceId'
    
     #List IAM UserName
     aws iam list-users | jq '.Users[].UserName'
    
  3. Change the file permission chmod u+x aws_resourceses_report.sh

  4. Download and configure AWS CLI.

  5. Execute the command. ./aws_resourceses_report.sh

  6. Now if we want that everyday at 9.00 AM morning our script should be executed automatically, we should create a cronjob.

  7. Install and start cron.

     sudo yum install  cronie
     systemctl start crond
    
  8. and create a cronjob.

     crontab -e
     # write the job
     0 9 * * * cd /home/ec2-user && ./aws_resourceses_report.sh >> resources_report
    

This script will be executed Everyday 9.00 AM and keeps the output in resources_report file.

Thnakyou for reading.

More from this blog

Vishal Kerketta

14 posts