Solved

Unix shell script question (goto - label)

Posted on 2003-10-29
5
3,011 Views
Last Modified: 2013-12-26
I am a novice shell script programmer, so be gentle!

Currently I have a automated process that uses about 10 separate Bourne shell scripts... One will execute, then fire off the next and so forth.
I want to consolidate the scripts into one, but I need to use some type of "goto" command to a label inside the script. I did not find any "goto" command in my Unix Shell programming book. I know that the "csh" uses "goto", but I was told not to use "csh".

Any suggestions?
0
Comment
Question by:rlburris
  • 3
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
yuzh earned 250 total points
ID: 9647955
If you want to merge all the scripts in one piece, define each script as a function of your
main script.
just make sure that you declear the fuction at the beginning of your script

eg.

a litter script:

#!/bin/ksh
# log something to a log file
LOGFILE=/var/log/mylog
echo "$1" >>$LOGFILE 2>&1
# END


Now we, write a main script and modify the above script as a function.

eg:

#!/bin/ksh
# VAR declarations
LOGFILE=/var/log/mylog

#........

# Functions

Log ()
{
  echo "$1" >>$LOGFILE 2>&1
}

# start of the main script
# do some thing

# use the function
Log "Subject: SUCCESS!: ${DAY} Backup log for SQL Server"

# do other things

exit

# END OF SCRIPT

Hope that it can help.
0
 

Author Comment

by:rlburris
ID: 9648079
Yuzh,
      Please explain (break down) the following command:
echo "$1" >> $LOGFILE 2>&1

Also when you use the function Log in your example... Does "Subject:SUCCESS!" writes to the LOGFILE?

0
 
LVL 38

Expert Comment

by:yuzh
ID: 9648170
Yes.
echo "$1" >> $LOGFILE

willl write "Subject: SUCCESS!: ${DAY} Backup log for SQL Server" to $LOGFILE
in this case is /var/log/mylog (I defined it before the function)

echo "$1" >> $LOGFILE 2>&1

will write "Subject: SUCCESS!: ${DAY} Backup log for SQL Server" + any
error message to the login file (I redirect stderr to stdin)
0
 

Author Comment

by:rlburris
ID: 9648468
Thanks yuzh!!!
0
 
LVL 38

Expert Comment

by:yuzh
ID: 9648474
You are welcome.

Cheers!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 145
unable to delete all specified values regedit 38 539
centeredAverage challenge 8 178
post4 challenge 28 104
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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