Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Shell scripting question

Posted on 2013-05-24
6
Medium Priority
?
395 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 20

Accepted Solution

by:
simon3270 earned 2000 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

Independent Software Vendors: 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

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…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

636 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