Solved

Shell scripting question

Posted on 2013-05-24
6
390 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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