Solved

Shell scripting question

Posted on 2013-05-24
6
383 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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…

707 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

17 Experts available now in Live!

Get 1:1 Help Now