Twitter

Some bash tips -- 0 -- Introduction / menu

I have always been coding more or less in my life producing some useful scripts mainly for the Oracle community. During the last 1+ year, I have coded more for a big project to move data from Teradata to Google Cloud and also participated in this Google open source project.

Coding more and for more intensively used scripts made me faced new problems and then found new solutions / tips which I now apply in every of my scripts. Indeed, it is not because a script is not heavily used every 5 minutes to move TBs of data from a system A to a system B that it does no deserve to be nice and robust.

These below tips do not pretend to be exhaustive nor to be a kind of ulimate shell guide nor to be super obfuscated rocket science, it is just few tips I found very useful to know and to use in every script you could write to make them nice, easily maintainable and robust:

7 comments:

  1. Thank you for yours scripts and posts.!

    ReplyDelete
  2. Hi Sir,
    I'm a regular follower of your blog. This series of bash knowledge is really fantastic for me. I'm eagerly waiting for rest of the articles.

    Thannk you

    ReplyDelete
    Replies
    1. Thanks a lot ! I add some as they come :)

      If you have any specific topic you would like to be documented here, let me know.

      Delete
  3. Hi Sir,
    Hope you are good and healthy.

    I have developed one shell script to loop through all my pdb's (Pluggable databases) to get the health details like Tablespaces, Invalid objects, long running etc.

    The script is failing to execute. Please let me know what i need to do to loop through all my PDBS. My CDB contains 4 pdbs

    Script
    =======
    export ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/dbhome_1
    export PATH=$ORACLE_HOME/bin:$PATH
    export TNS_ADMIN=/home/oracle/monitoring_scripts

    ### connecting CDB here
    ${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" < 2 AND open_mode = 'READ WRITE' ORDER BY 1
    EOF)
    do
    (${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" <<EOF
    alter session set container=${PDB};
    @/home/oracle/monitoring_scripts/pdb_health.sql
    spool off
    EOF
    )
    done

    Error
    ======
    ./monitor_space_2.sh: line 11: syntax error near unexpected token `('
    ./monitor_space_2.sh: line 11: `for PDB in (${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" <<EOF'






    ReplyDelete
    Replies
    1. Like this:

      for PDB in $(sqlplus -S / as sysdba << END
      set head off ;
      set feed off ;
      select name from v\$pdbs where open_mode = 'READ WRITE' ;
      END
      ); do
      echo $PDB;
      sqlplus -S / as sysdba << END
      alter session set container="${PDB}" ;
      show con_name ;
      END
      done

      Delete
    2. PS: the heredoc must not have anything behind:

      for PDB in $(sqlplus -S / as sysdba << END
      set head off ;
      set feed off ;
      select name from v\$pdbs where open_mode = 'READ WRITE' ;
      END); do <=== wrong


      for PDB in $(sqlplus -S / as sysdba << END
      set head off ;
      set feed off ;
      select name from v\$pdbs where open_mode = 'READ WRITE' ;
      END <== good
      ); do

      Delete
    3. Thank you very much for your update sir. I'll try your code and let you know the status.

      Delete

CUDA: getting started on WSL

I have always preferred command line and vi finding it more efficient so after the CUDA: getting started on Windows , let's have a loo...