Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-18-2005, 04:14 PM   #1
LQ Newbie
Registered: Dec 2004
Posts: 6

Rep: Reputation: 0
shell scripts


I would appreciate help with the following. I am writing a shell script
that call several different perl files.

To be exact let us say that I am calling four perl files. We will call
them,,, and

I want to run them in the following order:,,,

If both and do not run properly I don't want to run, or

If both and run okay but does not run properly I don't want
to run

Each time ther is an error I want to report it in a log file.

I would like to know the best way of doing this in a shell script.
Also, is there something better I can do instead of just writing an
error to the log file.
One of the perl files that I am calling is loading a database.
If the loading doesn't work properly I would like to roll back instead
of having an improper loading.

thank in advance!
Old 01-18-2005, 05:38 PM   #2
Registered: Jan 2004
Location: USA
Distribution: macOS, OpenBSD
Posts: 669

Rep: Reputation: 34
I have a couple of links that i found useful in writing my shell scripts for bash:

Beginner's guide:

Advanced guide (more indepth than the one above):

And another:

And something i found very quick and easy for variables in bash:

Shell scripts basically run commands from the console except you can put them into a script and manipulate multiple commands, set variables, make loops (for repeated commands that would otherwise be tedious), read and write to files easily, etc.

For example the command
$ echo "My name is Alex" >> ~/tmp/name.txt
would do the same thing as
# This is the script
echo "My name is Alex" >> ~/tmp/name.txt
Now you can modify that and use command line arguments like
# "$1" is the first command line argument indicating
# the name of the file to store this text in the folder ~/tmp/
echo "My name is Alex" >> ~/tmp/$1
It would be run like this:
$ sh filename.txt
$ ./ filename.txt

Last edited by student04; 01-18-2005 at 05:40 PM.
Old 01-18-2005, 06:44 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,308

Rep: Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744
Try this:

for file in `ls -1 *.pl`
    if [[ $? -ne 0 ]]
        echo "$file failed"
For a DB rollback, you'll have to do that inside the perl prog.

Here's an email submit fn you could use:
function mail_msg()
    # Get params & set local vars
    NODE=`uname -n`

    echo "$MSG" | mail -s "$NODE:$SUBJECT" $MAILTO
    if [[ $? -ne 0 ]]
        exit_with_error "Failed to email $NODE:$SUBJECT $MSG $MAILTO"
function exit_with_error()
    echo -e "$0 exiting with error. Msg was:\n$1"
    exit 1
call it like this
    mail_msg "$0: Unable to <your msg here> " "$0: Failed !"

Last edited by chrism01; 01-18-2005 at 06:50 PM.
Old 01-18-2005, 08:12 PM   #4
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
Maybe I'm just being a little too simplistic on this...
Couldn't you just do this: && && && || mail -s "the script failed" < /dev/null

Check this out:


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with shell scripts thorney Linux - Newbie 4 11-27-2005 11:18 PM
Shell Scripts benwy Linux - Software 1 06-09-2003 02:58 AM
Shell scripts anon227 Linux - Software 1 01-03-2003 03:11 PM
shell scripts nautilus_1987 Linux - General 3 08-30-2002 03:12 AM
shell scripts gui10 Programming 10 10-28-2001 02:46 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:34 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration