Showing posts with label scripts. Show all posts
Showing posts with label scripts. Show all posts

Tuesday, 14 September 2021

script - Mount point details on mail with attachements


script - Mount point details on mail  with attachments

  • Mail message Template ;

  
 

oracle@test08:/u02/scripts> cat template.tmp


Space disk details df -h on xxxxxxpl08 server!!!


ip address - 10.10.10.10


  • Script details 

 

oracle@test08:/u02/scripts> cat mount_point_mail.sh




df -h | awk '{print strftime("date +%d_%m_%y_%H_%M_%S"), $1, $2, $3,$4,$5}' | column -t >> /u02/scripts/mountpoint_output.log




mailx -a mountpoint_output.log -s " TESTING MOUNT POINT test08 " varun.yadav@xxxx.com<template.tmp




exit


oracle@test08:/u02/scripts>


  • OUTPUT: 
  •  
    
    




    Friday, 13 March 2020

    Example Script to delete old dump files or archive log based on time and minutes

     ---------------  steps for removing old alert log files ---------------


    1. Go to alert log file directory
     cd /u01/app/oracle/diag/rdbms/smrprodb_dr/PRODB/trace

    mkdir /u01/app/oracle/diag/rdbms/smrprodb_dr/PRODB/trace/alert_backup_logs

    2. create housekeeping_alert.sh files

    cd /u04/DB/scripts/

    vi housekeeping_alert.sh

    oracle@s1:/u04/DB/scripts> cat housekeeping_alert.sh
    export ORACLE_BASE=/u02/app/oracle
    export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1
    export ORACLE_SID=PRODB
    export PATH=$PATH:$ORACLE_HOME/bin

    #location of alert log files
    cd /u01/app/oracle/diag/rdbms/prodb_dr/PRODB/trace
    #Moving log files
    mv /u01/app/oracle/diag/rdbms/prodb_dr/PRODB/trace/alert_RODB*.log /u01/app/oracle/diag/rdbms/prodb_dr/PRODB/trace/alert_backup_logs

    #Granting permissions for Dump files
    chmod -R 775 /u01/app/oracle/diag/rdbms/prodb_dr/PRODB/trace/alert_backup_logs/

    #Compressing files

    gzip /u01/app/oracle/diag/rdbms/prodb_dr/PRODB/trace/alert_backup_logs/*.log*

    #Removing 60 days old dump files
    find /u01/app/oracle/diag/rdbms/smrprodb_dr/SMRPRODB/trace/alert_backup_logs/ -mtime +60 -exec rm {} \;

    #Removing 1440 minute old archive log files ####################

    #find /u01/app/oracle/fast_recovery_area/RAC/archivelog/*.arc -mmin +1440 -exec rm {} \;

    3.  chmod 777 housekeeping_alert.sh

    oracle@s:/u04/MDB/scripts>

    4. schedule it on crontab it will run on every month (next at 2017-10-01 00:00:00)

    crontab -e

    0 0 1 * *  /u04/MDB/scripts/housekeeping_alert.sh

    $$$$$$$$$$$$$$ Archive log delete output Example ###########################


    find /u01/app/oracle/fast_recovery_area/RAC/archivelog/*.arc -mmin +1440 -exec rm {} \;

    oracle@s08:~> cd /u01/app/oracle/fast_recovery_area/RAC/archivelog/
    oracle@s08:/u01/app/oracle/fast_recovery_area/SMRRAC/archivelog> ls -ltr
    total 4382064
    -rw-r----- 1 oracle oinstall     70144 Mar 12 07:18 arch_2_843_1020157972.arc
    -rw-r----- 1 oracle oinstall 247096320 Mar 12 07:18 arch_1_1190_1020157972.arc
    -rw-r----- 1 oracle oinstall 244623360 Mar 12 07:18 arch_1_1191_1020157972.arc
    -rw-r----- 1 oracle oinstall 244738048 Mar 12 07:18 arch_1_1192_1020157972.arc
    -rw-r----- 1 oracle oinstall 176008704 Mar 12 07:18 arch_2_844_1020157972.arc
    -rw-r----- 1 oracle oinstall 245496320 Mar 12 07:32 arch_1_1193_1020157972.arc
    -rw-r----- 1 oracle oinstall 244393472 Mar 12 07:32 arch_1_1194_1020157972.arc
    -rw-r----- 1 oracle oinstall 244472320 Mar 12 07:32 arch_1_1195_1020157972.arc
    -rw-r----- 1 oracle oinstall  84999680 Mar 12 07:32 arch_2_845_1020157972.arc
    -rw-r----- 1 oracle oinstall 244384256 Mar 12 07:32 arch_1_1196_1020157972.arc
    -rw-r----- 1 oracle oinstall  27237376 Mar 12 07:32 arch_2_846_1020157972.arc
    -rw-r----- 1 oracle oinstall 255912448 Mar 12 07:52 arch_1_1197_1020157972.arc
    -rw-r----- 1 oracle oinstall  72956928 Mar 12 07:52 arch_1_1198_1020157972.arc
    -rw-r----- 1 oracle oinstall     45056 Mar 12 07:52 arch_1_1199_1020157972.arc
    -rw-r----- 1 oracle oinstall     96256 Mar 12 07:52 arch_1_1200_1020157972.arc
    -rw-r----- 1 oracle oinstall 175212544 Mar 12 07:52 arch_2_847_1020157972.arc
    -rw-r----- 1 oracle oinstall     13312 Mar 12 07:52 arch_2_849_1020157972.arc
    -rw-r----- 1 oracle oinstall     45568 Mar 12 07:52 arch_2_848_1020157972.arc
    -rw-r----- 1 oracle oinstall 244402688 Mar 13 07:51 arch_1_1201_1020157972.arc
    -rw-r----- 1 oracle oinstall 244753920 Mar 13 07:51 arch_1_1202_1020157972.arc
    -rw-r----- 1 oracle oinstall 244624384 Mar 13 07:51 arch_1_1203_1020157972.arc
    -rw-r----- 1 oracle oinstall 177154560 Mar 13 07:52 arch_2_850_1020157972.arc
    -rw-r----- 1 oracle oinstall 244860928 Mar 13 07:52 arch_1_1204_1020157972.arc
    -rw-r----- 1 oracle oinstall 245518848 Mar 13 07:52 arch_1_1205_1020157972.arc
    -rw-r----- 1 oracle oinstall 246188032 Mar 13 07:52 arch_1_1206_1020157972.arc
    -rw-r----- 1 oracle oinstall  87497216 Mar 13 07:52 arch_2_851_1020157972.arc
    -rw-r----- 1 oracle oinstall 244379648 Mar 13 07:52 arch_1_1207_1020157972.arc
    oracle@sgdcpl08:/u01/app/oracle/fast_recovery_area/SMRRAC/archivelog> find /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/*.arc -mtime +1 -exec rm {} \;
    oracle@sgdcpl08:/u01/app/oracle/fast_recovery_area/SMRRAC/archivelog> ll
    total 4382064
    -rw-r----- 1 oracle oinstall 247096320 Mar 12 07:18 arch_1_1190_1020157972.arc
    -rw-r----- 1 oracle oinstall 244623360 Mar 12 07:18 arch_1_1191_1020157972.arc
    -rw-r----- 1 oracle oinstall 244738048 Mar 12 07:18 arch_1_1192_1020157972.arc
    -rw-r----- 1 oracle oinstall 245496320 Mar 12 07:32 arch_1_1193_1020157972.arc
    -rw-r----- 1 oracle oinstall 244393472 Mar 12 07:32 arch_1_1194_1020157972.arc
    -rw-r----- 1 oracle oinstall 244472320 Mar 12 07:32 arch_1_1195_1020157972.arc
    -rw-r----- 1 oracle oinstall 244384256 Mar 12 07:32 arch_1_1196_1020157972.arc
    -rw-r----- 1 oracle oinstall 255912448 Mar 12 07:52 arch_1_1197_1020157972.arc
    -rw-r----- 1 oracle oinstall  72956928 Mar 12 07:52 arch_1_1198_1020157972.arc
    -rw-r----- 1 oracle oinstall     45056 Mar 12 07:52 arch_1_1199_1020157972.arc
    -rw-r----- 1 oracle oinstall     96256 Mar 12 07:52 arch_1_1200_1020157972.arc
    -rw-r----- 1 oracle oinstall 244402688 Mar 13 07:51 arch_1_1201_1020157972.arc
    -rw-r----- 1 oracle oinstall 244753920 Mar 13 07:51 arch_1_1202_1020157972.arc
    -rw-r----- 1 oracle oinstall 244624384 Mar 13 07:51 arch_1_1203_1020157972.arc
    -rw-r----- 1 oracle oinstall 244860928 Mar 13 07:52 arch_1_1204_1020157972.arc
    -rw-r----- 1 oracle oinstall 245518848 Mar 13 07:52 arch_1_1205_1020157972.arc
    -rw-r----- 1 oracle oinstall 246188032 Mar 13 07:52 arch_1_1206_1020157972.arc
    -rw-r----- 1 oracle oinstall 244379648 Mar 13 07:52 arch_1_1207_1020157972.arc
    -rw-r----- 1 oracle oinstall     70144 Mar 12 07:18 arch_2_843_1020157972.arc
    -rw-r----- 1 oracle oinstall 176008704 Mar 12 07:18 arch_2_844_1020157972.arc
    -rw-r----- 1 oracle oinstall  84999680 Mar 12 07:32 arch_2_845_1020157972.arc
    -rw-r----- 1 oracle oinstall  27237376 Mar 12 07:32 arch_2_846_1020157972.arc
    -rw-r----- 1 oracle oinstall 175212544 Mar 12 07:52 arch_2_847_1020157972.arc
    -rw-r----- 1 oracle oinstall     45568 Mar 12 07:52 arch_2_848_1020157972.arc
    -rw-r----- 1 oracle oinstall     13312 Mar 12 07:52 arch_2_849_1020157972.arc
    -rw-r----- 1 oracle oinstall 177154560 Mar 13 07:52 arch_2_850_1020157972.arc
    -rw-r----- 1 oracle oinstall  87497216 Mar 13 07:52 arch_2_851_1020157972.arc
    oracle@s08:/u01/app/oracle/fast_recovery_area/RAC/archivelog> find /u01/app/oracle/fast_recovery_area/RAC/archivelog/*.arc -mmin +1440
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_1_1190_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_1_1191_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_1_1192_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_1_1193_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_1_1194_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_1_1195_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_1_1196_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_1_1197_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_1_1198_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_1_1199_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_1_1200_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_2_843_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_2_844_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_2_845_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_2_846_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_2_847_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_2_848_1020157972.arc
    /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/arch_2_849_1020157972.arc
    oracle@sgdcpl08:/u01/app/oracle/fast_recovery_area/SMRRAC/archivelog> find /u01/app/oracle/fast_recovery_area/SMRRAC/archivelog/*.arc -mmin +1440 -exec rm {} \;
    oracle@s08:/u01/app/oracle/fast_recovery_area/SMRRAC/archivelog> ls -ltr
    total 1933004
    -rw-r----- 1 oracle oinstall 244402688 Mar 13 07:51 arch_1_1201_1020157972.arc
    -rw-r----- 1 oracle oinstall 244753920 Mar 13 07:51 arch_1_1202_1020157972.arc
    -rw-r----- 1 oracle oinstall 244624384 Mar 13 07:51 arch_1_1203_1020157972.arc
    -rw-r----- 1 oracle oinstall 177154560 Mar 13 07:52 arch_2_850_1020157972.arc
    -rw-r----- 1 oracle oinstall 244860928 Mar 13 07:52 arch_1_1204_1020157972.arc
    -rw-r----- 1 oracle oinstall 245518848 Mar 13 07:52 arch_1_1205_1020157972.arc
    -rw-r----- 1 oracle oinstall 246188032 Mar 13 07:52 arch_1_1206_1020157972.arc
    -rw-r----- 1 oracle oinstall  87497216 Mar 13 07:52 arch_2_851_1020157972.arc
    -rw-r----- 1 oracle oinstall 244379648 Mar 13 07:52 arch_1_1207_1020157972.arc

    oracle@08:/u01/app/oracle/fast_recovery_area/SMRRAC/archivelog>




    Monday, 3 February 2020

    LDAP Backup Scripts

    #!/bin/bash
    #
    # version 1.0,

    #-------------------------------------------------------------
    # directory to backup to
    BACKDIR="/backups"
    BACKDIR_physical="$BACKDIR/physical"
    BACKDIR_logical="$BACKDIR/logical"
    #  your LDAP server's name
    ##SERVER=cadir.nic.in
    # date format that is appended to filename
    DATE=`date +'%m-%d-%Y-T-%H:%M:%S'`
    # your tape device
    tape_device=/dev/st0
    #tape_device=/dev/null
    #DEST=" "
    #-------------------------------------------------------------
    # Source function library.
    . /etc/init.d/functions

    #slapd=/usr/sbin/slapd
    #slurpd=/usr/sbin/slurpd
    #[ -x ${slapd} ] || exit 0
    RETVAL=0
    LDAPFILES=/var/lib/ldap/

    #-------------------Starting LDAP service-----------------------
    function start() {
            # Start daemons.
            echo -n "Starting slapd:"
    /etc/init.d/ldap start
            #daemon ${slapd}
            RETVAL=$?
            echo
            return $RETVAL
    }

    #----------------Stop LDAP service-----------------------------
    function stop() {
            # Stop daemons.
    echo -e "This is a test message"
            echo -e "Shutting down ldap: "
            #killproc ${slapd}
    /etc/init.d/ldap stop
            RETVAL=$?
            return $RETVAL
    }

    function cptotape() {
            # Copying data to Tape.
            echo -n "Please check tape is inserted ..."
      #echo $tape_device
      #echo $DEST
            #tar -vzrf $tape_device $DEST
            echo -n "Copying data to Tape ..."
            echo
            return $RETVAL
    }

    #----------------------Mail Settings--------------------#
    # set to 'y' if you'd like to be emailed the backup (requires mutt)
    MAIL=N
    # email addresses to send backups to, separated by a space
    EMAILS="user@gmail.com user@inbox.com user@walla.com user@goowy.com"
    # email subject
    SUBJECT="LDAP Backup on $SERVER ($DATE)"
    #----------------------FTP Settings--------------------#
    # set "FTP=y" if you want to enable FTP backups
    FTP=N
    # FTP server settings; should be self-explanatory
    FTPHOST="ftp.server.com"
    FTPUSER="user"
    FTPPASS="password"
    # directory to backup to. if it doesn't exist, file will be uploaded to
    # first logged-in directory
    FTPDIR="backups"
    #-------------------Deletion Settings-------------------#
    # delete old files?
    DELETE=N
    # how many days of backups do you want to keep?
    DAYS=5
    #----------------------End of Settings------------------#
    # make sure script is run as root
    if [ $(whoami) != "root" ]
    then
      echo "You must be root to run this script."
      exit 1
    fi
    # check of the backup directory exists
    # if not, create it
    if  [ -e $BACKDIR ]
    then
    echo Backups directory already exists
    else
    mkdir $BACKDIR
    mkdir $BACKDIR_physical
    mkdir $BACKDIR_logical
    fi

    echo Backing up LDAP entries...
    if  [ $MAIL = "y" ]
    then
    BODY="Your backup is ready! "
    ATTACH=`for file in $BACKDIR/*$DATE.ldif; do echo -n "-a ${file} ";  done`

    echo "$BODY" | mutt -s "$SUBJECT" $ATTACH $EMAILS
         
    echo "Your backup has been emailed to you!"
    fi
    if  [ $FTP = "y" ]
    then
    cd $BACKDIR
    ATTACH=`for file in *$DATE.ldif; do echo -n -e "put ${file}\n"; done`

    ftp -nv <<EOF
    open $FTPHOST
    user $FTPUSER $FTPPASS
    cd $FTPDIR
    $ATTACH
    quit
    EOF
    fi
    if  [ $DELETE = "y" ]
    then
    find $BACKDIR -name "*.ldif" -mtime $DAYS -exec rm {} \;

    if  [ $DAYS = "1" ]
    then
    echo "Yesterday's backup has been deleted"
    else
    echo "The backup from $DAYS days ago has been deleted"
    fi
    fi
    #-------------------------------------------------------------
    # See how we were called.
    case "$1" in
        Physical)
    echo "Preparing for offline physical backup"
            DEST=$BACKDIR_physical/ldapbackup-$DATE.tar.gz
    stop
    [ $RETVAL -eq 0 ] && tar cvzf $DEST ${LDAPFILES}
    cptotape
    echo "=============================================="
    echo $tape_device
    echo $DEST
    tar rvf $tape_device $DEST
    [ $RETVAL -eq 0 ] && start
    echo "==============================================="
    ;;
        Logical)
    echo "Preparing for offline Logical backup in LDIF format"
            DEST=$BACKDIR_logical/ldapbackup-$DATE.ldif
    slapcat -l  $DEST
    cptotape
    echo $tape_device
    echo $DEST
    tar rvf $tape_device $DEST
    ;;
     
        *)
            echo "Usage: $0 Physical|Logical}"
            RETVAL=1
    esac
    echo Your backup is complete!