Solved

Unix shell script question (goto - label)

Posted on 2003-10-29
5
2,977 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks yuzh!!!
0
 
LVL 38

Expert Comment

by:yuzh
Comment Utility
You are welcome.

Cheers!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
paragon account problem 9 96
repeatEnd java challenge 42 83
sum67 challenge 35 89
has22 challenge 11 71
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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