• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 564
  • Last Modified:

Scripting

Hi,

Can any one help explain what all these lines mean at the top of an inherited script ?

A line by line break down will be rewarded points.  I will split points also if required.

Thanks in Advance Experts



$ more ulog_check.ksh
#!/usr/bin/ksh
#
#
#
#
eval WLOAD=`( cd \`dirname $0\` ; pwd | cut -f3 -d/)`
TIVHOME=/opt/Tivoli
LOG=/tmp/status_ulog.log
DISLOG=/tmp/disconnect.tmp
CONLOG=/tmp/connect.tmp
DISLOG_SORT=/tmp/disconnect.tmp.sort
CONLOG_SORT=/tmp/connect.tmp.sort
SWITCH_LOG=/tmp/switch.log
SWITCH_LOG_TMP=/tmp/switch_tmp.log
 
###############################################################################
# FUNCTION HEADER
#
# FUNCTION NAME:                Error
# PARAMETER DESCRIPTION:        $1 = Message to attach to logevent
# FUNCTION DESCRIPTION:         This function sends a logevent when an error
#                               condition is encountered
# RETURN CODES:                 none
# COMMENTS:                     none
###############################################################################
 
function error
{
        alert_msg=$1
        ${TIVHOME}/sbin/logevent -s ${WLOAD} -c CHRI_PATL -v CRITICAL -e SWIGATE_CD_0001 -m "$alert_msg"
}
 
###############################################################################
#MAIN BODY
###############################################################################
#
. /wload/${WLOAD}/app/opt/SWIGATE/netlinlk/admin/netlinkprofile
> ${DISLOG}
> ${CONLOG}
> ${CONLOG_SORT}
> ${DISLOG_SORT}
> ${LOG}
 
if [[ "$(date +'%a')" == "Sat" && "$(date +'%H')" > "16" && "$(date +'%H')" < "24" ]]
then
 exit
fi
0
Nicenchrisp
Asked:
Nicenchrisp
  • 2
2 Solutions
 
Gerwin Jansen, EE MVETopic Advisor Commented:
#!/usr/bin/ksh
This script will run with Korn Shell (Ksh)
eval WLOAD=`( cd \`dirname $0\` ; pwd | cut -f3 -d/)`
TIVHOME=/opt/Tivoli
LOG=/tmp/status_ulog.log
DISLOG=/tmp/disconnect.tmp
CONLOG=/tmp/connect.tmp
DISLOG_SORT=/tmp/disconnect.tmp.sort
CONLOG_SORT=/tmp/connect.tmp.sort
SWITCH_LOG=/tmp/switch.log
SWITCH_LOG_TMP=/tmp/switch_tmp.log
Setting variables
###############################################################################
# FUNCTION HEADER
#
# FUNCTION NAME:                Error
# PARAMETER DESCRIPTION:        $1 = Message to attach to logevent
# FUNCTION DESCRIPTION:         This function sends a logevent when an error
#                               condition is encountered
# RETURN CODES:                 none
# COMMENTS:                     none
###############################################################################
Comment
function error
{
        alert_msg=$1
        ${TIVHOME}/sbin/logevent -s ${WLOAD} -c CHRI_PATL -v CRITICAL -e SWIGATE_CD_0001 -m "$alert_msg"
}
Definition of a function called error
. /wload/${WLOAD}/app/opt/SWIGATE/netlinlk/admin/netlinkprofile
Starting a script or program called netlinkprofile
> ${DISLOG}
> ${CONLOG}
> ${CONLOG_SORT}
> ${DISLOG_SORT}
> ${LOG}
Empty a few files
if [[ "$(date +'%a')" == "Sat" && "$(date +'%H')" > "16" && "$(date +'%H')" < "24" ]]
then
 exit
fi
if statement that exits the script if the condition is met, makes not much sense because there are no more lines in the script (that you posted).
0
 
NicenchrispAuthor Commented:
Thanks Gerwinjansen,

However what is being set here ? eval WLOAD=`( cd \`dirname $0\` ; pwd | cut -f3 -d/)`
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
If you want to learn a bit, just split the command and see what it does :)

cd - change directory
dirname $0 - gets directory name of current script executed
pwd - print working directory
cut - split up in fields, in this case get 3rd field, spit using / characters

WLOAD is your variable that the result of the subshell commands between `( ... )` is assigned to
0
 
TintinCommented:
Most of the script is pretty standard, apart from the setting of WLOAD.


eval WLOAD=`( cd \`dirname $0\` ; pwd | cut -f3 -d/)` 

Open in new window


gerwinjansen has already broken it down for you, so I'll give you an example.

Say you call the script with

/path/to/the/script


$0 is set to /path/to/the/script

dirname $0 results in /path/to/the

so the first part would change directory to /path/to/the

The pwd would output the current working directory, ie: /path/to/the

The cut command would extract the third field delimited by /, which in this case is 'to'.

Intuitively, you might think it would be set to 'the', but because the delimited is the first character, effectively the first field is a null, so you have

1st field is: null
2nd field is: path
3rd field is: to
4th field is: the
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now