├── jiraid.txt ├── README.md ├── service.log ├── jira.html ├── frontend.log ├── basic_report.html ├── automation5.sh ├── include-file ├── test.sh ├── automation4.sh ├── automation6.sh ├── hit.sh ├── html ├── automation2.sh ├── automation7.sh ├── automation1.sh ├── automation3.sh ├── Exam.sh ├── FunctionsWithShell.sh └── docker.sh /jiraid.txt: -------------------------------------------------------------------------------- 1 | SA-1 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ShellScripting_Automation -------------------------------------------------------------------------------- /service.log: -------------------------------------------------------------------------------- 1 | This is a log file 2 | -------------------------------------------------------------------------------- /jira.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /frontend.log: -------------------------------------------------------------------------------- 1 | This is a frontened sample log file 2 | -------------------------------------------------------------------------------- /basic_report.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

My First Shell Scripting in DevOps

6 |

SINGAM BATCH 1.0.

7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /automation5.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | may_date=`date -d '2023-04-01 +30 days' '+%Y-%m-%d'` 3 | echo $may_date 4 | TWO=2 5 | april_date=`date -d '2023-04-03 -2 days' '+%Y-%m-%d'` 6 | echo $april_date 7 | -------------------------------------------------------------------------------- /include-file: -------------------------------------------------------------------------------- 1 | /Users/praveensingampalli/Documents/BOOTCAMP2_FINAL/ShellScripting_Automation/Log_Backup/frontend.log 2 | /Users/praveensingampalli/Documents/BOOTCAMP2_FINAL/ShellScripting_Automation/Log_Backup/service.log 3 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | Hi 2 | Hello how are you 3 | This is devops course 4 | From Singam 5 | 6 | My manager is good 7 | 8 | Manager is able to manage all things 9 | 10 | 11 | version=1.2.3.4 12 | 13 | tenth session will be handson 14 | -------------------------------------------------------------------------------- /automation4.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd /opt/logs/ 3 | find . -type f -name '*log*' -exec cp '{}' /opt/logs/Log_Backup \; 4 | cd /opt/logs/Log_Backup 5 | find /opt/logs/Log_Backup -type f -name '*log*' > include-file 6 | tar -cvf $(hostname)_$(date +%Y-%m-%d).tar.gz -T include-file 7 | exit 8 | -------------------------------------------------------------------------------- /automation6.sh: -------------------------------------------------------------------------------- 1 | /usr/sbin/sendmail -i -t << 2 | Subject: $1 server process status 3 | From: 4 | To: 5 | Hi Team, 6 | Please check for $1 service in TEST server which has $3 7 | process running with below list of KIT IDs 8 | $2 9 | Regards, 10 | ShineInCareer 11 | MESSAGE_END 12 | 13 | -------------------------------------------------------------------------------- /hit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | curl -X PUT -u "singampallipraveenkumar@gmail.com:XkO2YJUvaof4fsvLAqtM63EA"--data '{"update":{"labels":[{"add":"DEMO"}]}}' --header "Content-Type: application/json" "Authorization: Basic XkO2YJUvaof4fsvLAqtM63EA" https://singam.atlassian.net/rest/api/3/issue/SA-1 3 | 4 | -------------------------------------------------------------------------------- /html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

MODULE_VERSION - {{module_version}}

4 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /automation2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | version="1.2.3.4" 3 | for line in $(cat jiraid.txt) 4 | do 5 | curl -X PUT -u "your_atlassian_jira_username:your_atlassian_jira_token" --data '{"update":{"labels":[{"add":"DEMO_NEW"}]}}' -H "Content-Type: application/json" https://singam.atlassian.net/rest/api/3/issue/$line 6 | done 7 | -------------------------------------------------------------------------------- /automation7.sh: -------------------------------------------------------------------------------- 1 | #SEND AN EMAIL TO TEAM AFTER THE VERSION IS INCREMENTED 2 | cat > jira.html <<'EOF' 3 | 4 | 5 |

MODULE_VERSION - {{module_version}}

6 |
Key
9 | 10 | 11 | 12 | EOF 13 | # MULTIPLE FILES READ 14 | paste jiraid.txt version.txt | while read take; do 15 | cat >> jira.html < 17 | 18 | 19 | 20 | EOF 21 | done 22 | -------------------------------------------------------------------------------- /automation1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | CICD=true 3 | WORKSPACE=/opt/ 4 | JOB_BASE_NAME=Test_demo 5 | BUILD_NUMBER=10 6 | if [ $CICD = true ] 7 | then 8 | echo "CI/CD pipe line check" 9 | file="${WORKSPACE}/basic_report.html" 10 | REPORTNAME=${JOB_BASE_NAME}_${BUILD_NUMBER}.Test_demo_10 11 | echo "CICD Check starting" 12 | if [ -f "$file" ]; then 13 | echo "testReport file found sending to artifactory" 14 | #curl -H X-JFrog-Art-Api:Token -T $file https://oneartifactorycloud/artifactory/CICD/Reports/$REPORTNAME.html 15 | else 16 | echo "testReport file not found" 17 | fi 18 | fi 19 | -------------------------------------------------------------------------------- /automation3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | array=(helloservice hiservice nameservice managerservice teamservice) 3 | for line in "${array[@]}" 4 | do 5 | COUNT=`ps -ef | grep helloservice | grep -v grep | wc -l`. RUNNING , 3 6 | MAX=2 7 | echo $line 8 | echo $COUNT 9 | if [ $COUNT -gt $MAX ] 10 | then 11 | echo $line 12 | PROCS=`ps -ef| grep $line | grep -v grep | awk '{print $2, $11, $12, $13}' | sort -k 4` 13 | JAR=`echo "${PROCS}" | awk -F"-Djar_name=| " '{print $5}'` 14 | echo $JAR 15 | JAR_RUN=`echo $JAR | sed 's/ /,/g'` 16 | echo $JAR_RUN 17 | cd /apps/nnos/test/scripts 18 | ./mail.sh $line $JAR_RUN $COUNT 19 | fi 20 | done 21 | -------------------------------------------------------------------------------- /Exam.sh: -------------------------------------------------------------------------------- 1 | Write a shell script to read the data from below log file and get the ip address 2 | 3 | https://www.onlinegdb.com/online_bash_shell 4 | 5 | 6 | 7 | 03/22 08:51:06 TRACE :...read_physical_netif: Home list entries returned = 7 8 | 03/22 08:51:06 INFO :...read_physical_netif: index #0, interface VLINK1 has address 129.1.1.1, ifidx 0 9 | 03/22 08:51:06 INFO :...read_physical_netif: index #1, interface TR1 has address 9.37.65.139, ifidx 1 10 | 03/22 08:51:06 INFO :...read_physical_netif: index #2, interface LINK11 has address 9.67.100.1, ifidx 2 11 | 03/22 08:51:06 INFO :...read_physical_netif: index #3, interface LINK12 has address 9.67.101.1, ifidx 3 12 | 03/22 08:51:06 INFO :...read_physical_netif: index #4, interface CTCD0 has address 9.67.116.98, ifidx 4 13 | 03/22 08:51:06 INFO :...read_physical_netif: index #5, interface CTCD2 has address 9.67.117.98, ifidx 5 14 | 03/22 08:51:06 INFO :...read_physical_netif: index #6, interface LOOPBACK has address 127.0.0.1, ifidx 0 15 | 03/22 08:51:06 INFO :....mailslot_create: creating mailslot for timer 16 | 03/22 08:51:06 INFO :...mailbox_register: mailbox allocated for timer 17 | 18 | 19 | Desired Output 20 | 21 | 129.1.1.1 22 | 9.37.65.139 23 | 9.67.100.1 24 | 9.67.116.98 25 | -------------------------------------------------------------------------------- /FunctionsWithShell.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Function to find log files older than 7 days 4 | find_old_logs() { 5 | # Set the directory to search and the log file extension 6 | local directory="$1" 7 | local extension="$2" 8 | 9 | # Check if the directory exists 10 | if [ ! -d "$directory" ]; then 11 | echo "Directory $directory does not exist." 12 | exit 1 13 | fi 14 | 15 | # Find files older than 7 days 16 | find "$directory" -type f -name "*.$extension" -mtime +7 17 | } 18 | 19 | # Function to send an email with the log results 20 | send_email() { 21 | local email_subject="$1" 22 | local email_recipient="$2" 23 | local email_body="$3" 24 | 25 | echo -e "$email_body" | mail -s "$email_subject" "$email_recipient" 26 | } 27 | 28 | # Main script logic 29 | 30 | # Set your directory and email details 31 | log_directory="/path/to/logs" # Modify this with your log directory 32 | log_extension="log" # Modify this if your logs have a different extension 33 | email_recipient="recipient@example.com" # Modify with your recipient email 34 | email_subject="Logs Older Than 7 Days" # Subject for the email 35 | 36 | # Find the logs older than 7 days 37 | log_files=$(find_old_logs "$log_directory" "$log_extension") 38 | 39 | # Check if we found any old logs 40 | if [ -z "$log_files" ]; then 41 | email_body="No log files older than 7 days were found." 42 | else 43 | email_body="The following log files are older than 7 days:\n\n$log_files" 44 | fi 45 | 46 | # Send email 47 | send_email "$email_subject" "$email_recipient" "$email_body" 48 | 49 | echo "Email sent to $email_recipient with the results." 50 | -------------------------------------------------------------------------------- /docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Function to check if Docker is installed 4 | checkDockerInstalled() { 5 | if ! command -v docker &>/dev/null; then 6 | echo "Docker is not installed." 7 | return 1 8 | else 9 | echo "Docker is already installed." 10 | return 0 11 | fi 12 | } 13 | 14 | # Function to install Docker 15 | installDocker() { 16 | if ! checkDockerInstalled; then 17 | echo "##############################################################################################################################" 18 | echo "Docker is an open platform for developing, shipping, and running applications." 19 | echo "It enables you to separate your applications from your infrastructure so you can deliver software quickly." 20 | echo "" 21 | echo "Please select your operating system/distribution to install Docker:" 22 | echo "##############################################################################################################################" 23 | echo "" 24 | 25 | PS3="Select your OS/Distribution: " 26 | select os_option in \ 27 | "Ubuntu 20.04 or 22.04" \ 28 | "Debian" \ 29 | "CentOS" \ 30 | "Fedora" \ 31 | "Amazon Linux" \ 32 | "OpenSUSE" \ 33 | "Quit" 34 | do 35 | case $REPLY in 36 | 1) installDockerUbuntu ;; 37 | 2) installDockerDebian ;; 38 | 3) installDockerCentOS ;; 39 | 4) installDockerFedora ;; 40 | 5) installDockerAmazonLinux ;; 41 | 6) installDockerOpenSUSE ;; 42 | 7) exit ;; 43 | *) echo "Invalid selection, please try again..." ;; 44 | esac 45 | done 46 | else 47 | echo "Exiting script as Docker is already installed." 48 | exit 0 49 | fi 50 | } 51 | 52 | # Function to install Docker on Ubuntu 53 | installDockerUbuntu() { 54 | clear 55 | echo "Installing Docker on Ubuntu..." 56 | sudo apt update 57 | sudo apt install -y docker.io 58 | echo "Docker installed successfully!" 59 | exit 0 60 | } 61 | 62 | # Function to install Docker on Debian 63 | installDockerDebian() { 64 | clear 65 | echo "Installing Docker on Debian..." 66 | sudo apt update 67 | sudo apt install -y docker.io 68 | echo "Docker installed successfully!" 69 | exit 0 70 | } 71 | 72 | # Function to install Docker on CentOS 73 | installDockerCentOS() { 74 | clear 75 | echo "Installing Docker on CentOS..." 76 | sudo yum install -y docker 77 | sudo systemctl start docker 78 | sudo systemctl enable docker 79 | echo "Docker installed successfully!" 80 | exit 0 81 | } 82 | 83 | # Function to install Docker on Fedora 84 | installDockerFedora() { 85 | clear 86 | echo "Installing Docker on Fedora..." 87 | sudo dnf install -y docker 88 | sudo systemctl start docker 89 | sudo systemctl enable docker 90 | echo "Docker installed successfully!" 91 | exit 0 92 | } 93 | 94 | # Function to install Docker on Amazon Linux 95 | installDockerAmazonLinux() { 96 | clear 97 | echo "Installing Docker on Amazon Linux..." 98 | sudo yum install -y docker 99 | sudo systemctl start docker 100 | sudo systemctl enable docker 101 | echo "Docker installed successfully!" 102 | exit 0 103 | } 104 | 105 | # Function to install Docker on OpenSUSE 106 | installDockerOpenSUSE() { 107 | clear 108 | echo "Installing Docker on OpenSUSE..." 109 | sudo zypper install -y docker 110 | sudo systemctl start docker 111 | sudo systemctl enable docker 112 | echo "Docker installed successfully!" 113 | exit 0 114 | } 115 | 116 | # Call the installDocker function to start the installation process 117 | installDocker 118 | --------------------------------------------------------------------------------
Key
$read$take