Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unix shell script question (goto - label)

Posted on 2003-10-29
5
Medium Priority
?
3,082 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
[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
5 Comments
 
LVL 38

Accepted Solution

by:
yuzh earned 1000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

704 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