Solved

Shell scripting question

Posted on 2013-05-24
6
386 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now