Solved

Shell scripting question

Posted on 2013-05-24
6
391 Views
Last Modified: 2013-05-24
I am new to unix, can someone explain what line is doing in the below code.

  echo "$1" "***FATAL*** EXCEPTIONS FOUND AT:" `date "+%e-%b-%Y %T"`|awk '{printf "%-30s%s %s %s %s %s %s\n",$1,$2,$3,$4,$5,$6,$7}'>>$tradehome/$log/summary.log


#!/bin/ksh -xv
#ods_fatal_check.sh started
#
fatal_count=`sqlplus -s $odsuser/$odspass @$tradehome/$plsql/endofday/start_ods_fatal_check.sql $1`; export fatal_count
   if ( test $fatal_count -ne 0)
   then
     echo "$1" "***FATAL*** EXCEPTIONS FOUND AT:" `date "+%e-%b-%Y %T"`|awk '{printf "%-30s%s %s %s %s %s %s\n",$1,$2,$3,$4,$5,$6,$7}'>>$tradehome/$log/summary.log
      $tradehome/$sh/ftp_summary_log.sh
      touch $tradehome/$log/odsfailed.dat
      exit
   fi
#ods_fatal_check.sh finished

Open in new window

0
Comment
Question by:d27m11y
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 26

Expert Comment

by:pony10us
ID: 39194537
There isn't enough information to be very detailed however a top level view of this line is that it puts an entry in the $tradehome/$log/summary.log file when there are "***FATAL*** EXCEPTIONS" found from running the script. If none are found then no entry is made.
0
 

Author Comment

by:d27m11y
ID: 39194545
May I know what this awk is trying to do in the above shell

echo "$1" "***FATAL*** EXCEPTIONS FOUND AT:" `date "+%e-%b-%Y %T"`|awk '{printf "%-30s%s %s %s %s %s %s\n",$1,$2,$3,$4,$5,$6,$7}'>>$tradehome/$log/summary.log

Open in new window

0
 
LVL 26

Expert Comment

by:pony10us
ID: 39194634
awk '{printf "%-30s%s %s %s %s %s %s\n",$1,$2,$3,$4,$5,$6,$7}'>>$tradehome/$log/summary.log

this is the part that is telling it to print an entry in the log file.  

Please refer to this for an explanation as it will do a better job than me trying to type one out  :)  

http://www.gnu.org/software/gawk/manual/html_node/Printf-Examples.html
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 39194639
$1 is the first parameter to the script.  The same value is passed to the start_ods_fatal_check.sql script in the "fatal_count=`...." line.

The line you are interested in first echos that $1 parameter, and the text "***FATAL*** EXCEPTIONS FOUND AT: DD-MMM-YYYY HH:MM:SS" (the current date and time).  awk takes that echoed line as input.  It prints out the first parameter (the $1 value) in a 30-character space, left-justified, and then prints out the remaining six words on the line (the "***FATAL***", "EXCEPTIONS", "FOUND" "AT:", the date and the time) with a single space between each string.  That formatted output is then appended to the $tradehome/$log/summary.log file.

One common confusion here is the two "$1"s.  The one immediately after the echo is the first parameter of the shell script.  The one after the "awk" is the first word on the input line being processed by awk.
0
 

Author Closing Comment

by:d27m11y
ID: 39194658
This is very helpful.. thank you so much !
0
 
LVL 26

Expert Comment

by:pony10us
ID: 39194692
eloquently put simon.  I probably would have taken me writing a whole new book just to explain it as well as you did.   :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question