Posts

Showing posts from November, 2018

get status of previous command

We may need to know the status of previous command sometimes. Whether this is successed or this is failed.According to teh situation we may need to perform some operation.So for this we need to understand whether our command ran successfully or not. Here you go nohup bash $Script_Path/scripts/Customer_Trans.sh EXIT_STATUS=$? Now the status is in EXIT_STATUS . This will be 0 if the process ran successfully. if [ $EXIT_STATUS != 0 ] then echo "Automatic reconciliation process failedat : `date +%Y%m%d` ." | mailx -s "Monthly Reconcilation" $Mail_ID else echo "Automatic reconciliation process successfully  ended at : `date +%Y%m%d` ." | mailx -s "Monthly Reconcilation" $Mail_ID fi Hope this is clear to you .

send mail using shell script

Here shows how to send mails using shell script. This can be useful when you are trying to send a mail notification before or after any particular job. Here is the command echo "content of  mail  : `date +%Y%m%d` ." | mailx -s "subject of mail " $Mail_ID (mail ideg@gmail,com) Put this in a shell script and call it using ./shell_name.sh .

Call a shell script from another shell script

Shell script has .sh format. This document shows how to call a shell script from another shell script . This may be useful when you you need to call multiple shell scripts at same time. So while running a main shell, you can call others one by one. Suppose my target script folder is Script_Path=$HOME/Monthly_Reconciliation nohup bash $Script_Path/exec_insert_process_status.sh  If you would like to write the log of this command to a file  you can write it as nohup bash $Script_Path/exec_insert_process_status.sh  > log_file.log If you would like to add any more comment in that log do it by "add more cooments to earlier log " >> log_file.log

sql output to a csv file using shell scipt

We can simply take extract of an oracle sql statement to a csv file through a shell script. This can be used when we need to configure a job using crontab or so.Once crontab is configure to run the job, it will run the shell script and the shell will in turn run the sql statement and the same will create a csv file. Let's have a look at it. For this we need to create a shell script I am calling it as Transaction.sh # Path to generate the csv file csv_path=HOME/Monthly_Reconciliation echo &date # File name FILE="$csv_path/Customer_Settle_`date +%Y%m%d`.csv" export ORACLE_HOME=/opt/app/oracle/product/11.2/client_1 export ORACLE_SID=atlas_etl_bistg_srv(my sid , please use yours) sqlplus_folder="$ORACLE_HOME/bin" $sqlplus_folder/sqlplus -s username/password@database(dv1dmh/testdmh etc..)<<EOF SET PAGESIZE 0 SET NEWPAGE 0 SET COLSEP ',' SET LINESIZE 30000 SET FEEDBACK OFF SET TRIMSPOOL ON #SET TRIMOUT ON SET ECHO OFF SET VE...