LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-16-2008, 09:06 AM   #1
onthefritz
Member
 
Registered: Dec 2005
Location: Colorado
Distribution: Ubuntu, RHEL, openSUSE
Posts: 105

Rep: Reputation: 19
backup script early termination


I am writing a backup script and I would like to find a way (for error checking) to terminate the script early. I am using an if statement to check to see if /backup if a file instead of a directory. If it is, then I just want to terminate the script. That would keep me from wrapping the script in an if statement. Here is the if statement I am using:

Code:
    if [ -a /backup ];
    then
    echo "Warning: /backup is a file, not a directory"
    # here is where I want to terminate the script
    fi
So can anyone help me out?

Thanks

OTF
 
Old 06-16-2008, 09:25 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Code:
if [ -a /backup ];
then
    echo "Warning: /backup is a file, not a directory"
    exit 1 # it is convention to exit with a non-zero exit status to indicate failure
fi
 
Old 06-16-2008, 10:05 AM   #3
onthefritz
Member
 
Registered: Dec 2005
Location: Colorado
Distribution: Ubuntu, RHEL, openSUSE
Posts: 105

Original Poster
Rep: Reputation: 19
Thanks, I wont know how well it works until I can run some test though. I don't doubt that it will work.

Thanks

OTF
 
  


Reply



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 backup script. gtrawoger Linux - Software 2 07-17-2006 07:31 AM
backup script nitaish Linux - General 1 04-22-2005 11:31 AM
help with backup script dennis_89 Linux - Networking 2 06-29-2004 09:47 AM
shell script - trap program termination dnijaguar Linux - Software 0 07-19-2003 12:27 AM
backup script ixion Linux - Software 2 01-09-2003 06:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:20 AM.

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