Solved

Unix shell script question (goto - label)

Posted on 2003-10-29
5
3,028 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 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 76
Process filename extension 3 218
iSeries DB2 Query 2 101
has77  challenge 9 107
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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