USERID=$(id -u)
LOGS_FOLDER="/var/log/shellscript-logs"
SCRIPT_NAME=$(echo $0 | cut -d "." -f1)
LOG_FILE="$LOGS_FOLDER/$SCRIPT_NAME.log"


mkdir -p $LOGS_FOLDER
$(date)


for i in {1..100}
do
  echo $i
  exit 1
done
fi


#!/bin/bash

set -e

while IFS=read -r line
do
  echo $line
done < 17-set.sh









#!/bin/bash

echo "fetching list of s3 buckets"

# check aws cli config
aws sts get-caller-identity >/dev/null 2>&1
if [ $? -ne 0 ]; 
then 
  echo "AWS cli is not configured properly. Run 'aws configure' first."
fi

aws s3 ls

echo "Done"


sh greeting.sh morning "afterfnoon"


$a , $*---> both used to access all arguments passed t bash script

aws s3 ls


become sudo access 

ignore_errors: true
ignore_unreachable: true






- name: Find failed services
  hosts: all  # all servers
  become: yes
  tasks:
    - name: Get failed services
      shell: systemctl --failed --type=service --no-legend | awk '{print $1}'
      register: failed_services
      changed_when: false
    
    - name: display failed services
      debug:
        var: failed_services.stdout_lines
      
    - name: restart failed services
      service:
        name: "{{ item }}"
        state: restarted
      loop: "{{ failed_services.stdout_lines }}"
      when: failed_service.stdout_lines | length > 0
    
    - name: verify failed service again
      shell: systemctl --failed --type=service --no-legend 
      register: verify_status
      changed_when: false

    debug:
      var: verify_status.stdout_lines





- name: patch vulnerable package upgrade with minimal downtime
  hosts: all_servers
  become: yes
  serial: 10  # update 10 servers at a time
  any_errors_fatal: true

  vars:
    package_name: openssl # we need to update this package
    package_version: "1.1.1k" # need to update ths version
    dependent_service: httpd #package update tarvata restart cheyyalsina service

  tasks:

    - name: check current installed package version
      ansible.builtin.shell: rpm -q {{ package_name }}
      register: current_version
      changed_when: false # Check మాత్రమే కాబట్టి changed గా mark చేయదు.
      ignore_errors: true
    
    - name: Display current package version
      ansible.builtin.debug:
        msg: "{{ inventory_hostname }} current version: {{ current_version.stdout }}"
      
    - name: update package to required version
      ansible.builtin.yum:
        name: "{{ package_name }}-{{ package_version }}"
        state: present
      register: package_update

    - name: restart dependent service if only pakcage updated
      ansible.builtin.service:
        name: "{{ dependent_service }}"
        state: restarted
      when: package_update.changed

    - name: wait for service to come back
      ansible.builtin.service:
        port: 80
        timeout: 60
      when: package_update.changed

    - name: verify updated package version
      ansible.builtin.shell: rpm -q {{ package_name }}
      register: updated_version
      changed_when: false



