Link to home
Start Free TrialLog in
Avatar of jaisonshereen
jaisonshereen

asked on

Please explain this shell script !

ROOT@server# cat /home/oracledb/bin/cron_corp8_every_5_minutes
#!/bin/csh -f
source /home/oracledb/environments/production_db_c_shell_environment_dba

#date
#echo /home/oracledb/bin/cron_corp8_every_5_minutes has been executed

if (-e $SQL_CRON_HOME/tmp/cron_corp8_every_5_minutes_in_progress) then

  if (! -e $SQL_CRON_HOME/tmp/cron_corp8_every_5_minutes_in_progress_warned) then
    /usr/bin/touch $SQL_CRON_HOME/tmp/cron_corp8_every_5_minutes_in_progress_warned
    cat /home/oracledb/bin/IS_DBAS_email_and_pagers.mail_recipient > $SQL_CRON_HOME/tmp/test_connect_production.mail
    echo "From: asd@asd.com" >> $SQL_CRON_HOME/tmp/test_connect_production.mail
    echo "Subject: cron_corp8_every_5_minutes Apparently Hung" >> $SQL_CRON_HOME/tmp/test_connect_production.mail
    echo "" >> $SQL_CRON_HOME/tmp/test_connect_production.mail
    echo "cron_corp8_every_5_minutes Apparently Hung" >> $SQL_CRON_HOME/tmp/test_connect_production.mail
    /usr/lib/sendmail -t < $SQL_CRON_HOME/tmp/test_connect_production.mail
  endif

else

  if (-e $SQL_CRON_HOME/tmp/cron_corp8_every_5_minutes_in_progress_warned) then
    /usr/bin/rm $SQL_CRON_HOME/tmp/cron_corp8_every_5_minutes_in_progress_warned
  endif

  /usr/bin/touch $SQL_CRON_HOME/tmp/cron_corp8_every_5_minutes_in_progress

  cp /var/adm/messages /home/oracledb/bin/tmp/corp8_console_messages.current
  diff /home/oracledb/bin/tmp/corp8_console_messages.last /home/oracledb/bin/tmp/corp8_console_messages.current > /home/oracledb/bin/tmp/corp8_msg_diff
  if (! -z /home/oracledb/bin/tmp/corp8_msg_diff) then
    cat /home/oracledb/bin/IS_DBAS_email.mail_recipient > /home/oracledb/bin/tmp/corp8_msg.mail
    echo "From: asd@asd.com" >> /home/oracledb/bin/tmp/corp8_msg.mail
    echo "Subject: Excerpt From corp8: /var/adm/messages" >> /home/oracledb/bin/tmp/corp8_msg.mail
    echo "" >> /home/oracledb/bin/tmp/corp8_msg.mail
    cat /home/oracledb/bin/tmp/corp8_msg_diff >> /home/oracledb/bin/tmp/corp8_msg.mail
    #/usr/lib/sendmail -t < /home/oracledb/bin/tmp/corp8_msg.mail
  endif
  mv /home/oracledb/bin/tmp/corp8_console_messages.current /home/oracledb/bin/tmp/corp8_console_messages.last

  if (! -e $SQL_CRON_HOME/tmp/suspend_page_production_connect) then

    sqlplus -s cron/croncron@production @$SQL_CRON_HOME/test_connect > $SQL_CRON_HOME/tmp/test_connect_production
    if (! -z $SQL_CRON_HOME/tmp/test_connect_production) then

      touch $SQL_CRON_HOME/tmp/suspend_page_production_connect
      cat /home/oracledb/bin/IS_DBAS_email_and_pagers.mail_recipient > $SQL_CRON_HOME/tmp/test_connect_production.mail
      echo "Subject: No Connect To PRODUCTION Database" >> $SQL_CRON_HOME/tmp/test_connect_production.mail
      echo "" >> $SQL_CRON_HOME/tmp/test_connect_production.mail
      echo "PRODUCTION: No Connect" >> $SQL_CRON_HOME/tmp/test_connect_production.mail
      /usr/lib/sendmail -t < $SQL_CRON_HOME/tmp/test_connect_production.mail
      /bin/rm $SQL_CRON_HOME/tmp/test_connect_production.mail

    else

      sqlplus -s cron/croncron@production @$SQL_CRON_HOME/check_redologs.sql > $SQL_CRON_HOME/tmp/check_redologs_production
      if (! -z $SQL_CRON_HOME/tmp/check_redologs_production) then
        sleep 15
        sqlplus -s cron/croncron@production @$SQL_CRON_HOME/check_redologs.sql > $SQL_CRON_HOME/tmp/check_redologs_production
        if (! -z $SQL_CRON_HOME/tmp/check_redologs_production) then
          cat /home/oracledb/bin/IS_DBAS_email_and_pagers.mail_recipient > $SQL_CRON_HOME/tmp/check_redologs_production.mail
          echo "From: asd@asd.com" >> $SQL_CRON_HOME/tmp/check_redologs_production.mail
          echo "Subject: Production Archiver Failed" >> $SQL_CRON_HOME/tmp/check_redologs_production.mail
          echo "" >> $SQL_CRON_HOME/tmp/check_redologs_production.mail
          echo "PRODUCTION: Archiver Failed" >> $SQL_CRON_HOME/tmp/check_redologs_production.mail
          /usr/lib/sendmail -t < $SQL_CRON_HOME/tmp/check_redologs_production.mail
          /bin/rm $SQL_CRON_HOME/tmp/check_redologs_production.mail
        endif
      endif

      sqlplus -s user/password@production @$SQL_CRON_HOME/show_contention.sql > $SQL_CRON_HOME/tmp/contention_production
      if (! -z $SQL_CRON_HOME/tmp/contention_production) then
        cat /home/oracledb/bin/IS_DBAS_email.mail_recipient > $SQL_CRON_HOME/tmp/contention_production.mail
        echo "From: asd@asd.com"  >> $SQL_CRON_HOME/tmp/contention_production.mail
        echo "Subject: Database Lock Report: Production" >> $SQL_CRON_HOME/tmp/contention_production.mail
        echo "" >> $SQL_CRON_HOME/tmp/contention_production.mail
        cat $SQL_CRON_HOME/tmp/contention_production >> $SQL_CRON_HOME/tmp/contention_production.mail
        echo "" >> $SQL_CRON_HOME/tmp/contention_production.mail
        echo "This mail was generated automatically by oracle's cron job running on corp8." >> $SQL_CRON_HOME/tmp/contention_production.mail
        /usr/lib/sendmail -t < $SQL_CRON_HOME/tmp/contention_production.mail
        /bin/rm $SQL_CRON_HOME/tmp/contention_production.mail
      endif

      sqlplus -s user/password@production @$SQL_CRON_HOME/test.sql > $SQL_CRON_HOME/tmp/test_tmp_production
      diff $SQL_CRON_HOME/tmp/test_tmp_production_last $SQL_CRON_HOME/tmp/test_tmp_production > $SQL_CRON_HOME/tmp/test_tmp_production_diff
      cp $SQL_CRON_HOME/tmp/test_tmp_production $SQL_CRON_HOME/tmp/test_tmp_production_last
      if (! -z $SQL_CRON_HOME/tmp/test_tmp_production_diff) then
        cat /home/oracledb/bin/IS_DBAS_email.mail_recipient > $SQL_CRON_HOME/tmp/test_tmp_production.mail
        echo "From: asd@asd.com"  >> $SQL_CRON_HOME/tmp/test_tmp_production.mail
        echo "Subject: PRODUCTION Test Results" >> $SQL_CRON_HOME/tmp/test_tmp_production.mail
        echo "" >> $SQL_CRON_HOME/tmp/test_tmp_production.mail
        cat $SQL_CRON_HOME/tmp/test_tmp_production_diff >> $SQL_CRON_HOME/tmp/test_tmp_production.mail
        /usr/lib/sendmail -t < $SQL_CRON_HOME/tmp/test_tmp_production.mail
        /bin/rm $SQL_CRON_HOME/tmp/test_tmp_production.mail
      endif

      if (-e $SQL_CRON_HOME/tmp/send_auto_email.lst) then
        /bin/rm $SQL_CRON_HOME/tmp/send_auto_email.lst
      endif
      if (-e $SQL_CRON_HOME/tmp/make_auto_emails.sql) then
        /bin/rm $SQL_CRON_HOME/tmp/make_auto_emails.sql
      endif
      sqlplus -s user/password@production @$SQL_CRON_HOME/check_auto_email.sql
      if ((-e $SQL_CRON_HOME/tmp/send_auto_email.lst) && (! -z $SQL_CRON_HOME/tmp/send_auto_email.lst)) then
        sqlplus -s user/password@production @$SQL_CRON_HOME/tmp/make_auto_emails.sql
        chmod 700 $SQL_CRON_HOME/tmp/send_auto_email.lst
        $SQL_CRON_HOME/tmp/send_auto_email.lst
        /bin/rm $SQL_CRON_HOME/tmp/auto_email_*
      endif

      sqlplus -s user/password@production @$SQL_CRON_HOME/increment_cron_corp8_every_5_minutes_stats.sql

    endif
  endif


  if (! -e $SQL_CRON_HOME/tmp/suspend_page_development_connect) then

    sqlplus -s user/password@development @$SQL_CRON_HOME/test_connect > $SQL_CRON_HOME/tmp/test_connect_development
    if (! -z $SQL_CRON_HOME/tmp/test_connect_development) then

      touch $SQL_CRON_HOME/tmp/suspend_page_development_connect
      /usr/bin/cat /home/oracledb/bin/IS_DBAS_email_and_pagers.mail_recipient > $SQL_CRON_HOME/tmp/test_connect_development.mail
      echo "From: oracledb" >> $SQL_CRON_HOME/tmp/test_connect_development.mail
      echo "Subject: No Connect To DEVELOPMENT Database" >> $SQL_CRON_HOME/tmp/test_connect_development.mail
      echo "" >> $SQL_CRON_HOME/tmp/test_connect_development.mail
      echo "DEVELOPMENT: No Connect" >> $SQL_CRON_HOME/tmp/test_connect_development.mail
      /usr/lib/sendmail -t < $SQL_CRON_HOME/tmp/test_connect_development.mail
      /bin/rm $SQL_CRON_HOME/tmp/test_connect_development.mail

    else

      sqlplus -s user/password@development @$SQL_CRON_HOME/show_contention.sql > $SQL_CRON_HOME/tmp/contention_development
      if (! -z $SQL_CRON_HOME/tmp/contention_development) then
        /usr/bin/cat /home/oracledb/bin/IS_DBAS_email.mail_recipient > $SQL_CRON_HOME/tmp/contention_development.mail
        echo "From: asd@asd.com" >> $SQL_CRON_HOME/tmp/contention_development.mail
        echo "Subject: Database Lock Report: DEVELOPMENT" >> $SQL_CRON_HOME/tmp/contention_development.mail
        echo "" >> $SQL_CRON_HOME/tmp/contention_development.mail
        cat $SQL_CRON_HOME/tmp/contention_development >> $SQL_CRON_HOME/tmp/contention_development.mail
        echo "" >> $SQL_CRON_HOME/tmp/contention_development.mail
        echo "This mail was generated automatically by oracle's cron job running on corp8." >> $SQL_CRON_HOME/tmp/contention_development.mail
        /usr/lib/sendmail -t < $SQL_CRON_HOME/tmp/contention_development.mail
        /bin/rm $SQL_CRON_HOME/tmp/contention_development.mail
      endif

      sqlplus -s user/password@development @$SQL_CRON_HOME/test.sql > $SQL_CRON_HOME/tmp/test_tmp_development
      diff $SQL_CRON_HOME/tmp/test_tmp_development_last $SQL_CRON_HOME/tmp/test_tmp_development > $SQL_CRON_HOME/tmp/test_tmp_development_diff
      cp $SQL_CRON_HOME/tmp/test_tmp_development $SQL_CRON_HOME/tmp/test_tmp_development_last
      if (! -z $SQL_CRON_HOME/tmp/test_tmp_development_diff) then
        /usr/bin/cat /home/oracledb/bin/IS_DBAS_email.mail_recipient > $SQL_CRON_HOME/tmp/test_tmp_development.mail
        echo "From: asd@asd.com" >> $SQL_CRON_HOME/tmp/test_tmp_development.mail
        echo "Subject: DEVELOPMENT Test Results" >> $SQL_CRON_HOME/tmp/test_tmp_development.mail
        echo "" >> $SQL_CRON_HOME/tmp/test_tmp_development.mail
        cat $SQL_CRON_HOME/tmp/test_tmp_development_diff >> $SQL_CRON_HOME/tmp/test_tmp_development.mail
        /usr/lib/sendmail -t < $SQL_CRON_HOME/tmp/test_tmp_development.mail
        /bin/rm $SQL_CRON_HOME/tmp/test_tmp_development.mail
      endif

    endif
  endif

  /usr/bin/rm $SQL_CRON_HOME/tmp/cron_corp8_every_5_minutes_in_progress
endif

ASKER CERTIFIED SOLUTION
Avatar of jar3817
jar3817

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jaisonshereen
jaisonshereen

ASKER

what source /home/oracledb/environments/production_db_c_shell_environment_dba  will do ?
that basically includes that file. So any code in that file will get executed and any variables set will be available in the main script.
which files i need to cat and show u to explain this shell script for me ?
It is generated, I need script that created it.