Fedora Linux Support Community & Resources Center
  #1  
Old 16th March 2006, 07:07 PM
leaded Offline
Registered User
 
Join Date: May 2004
Posts: 373
Question Bash scripting question

I was asked to write a bash script for upgrading our OC4J application. They want me to add an option to not back up a specific directory. There's a folder called application-deployments/iemp/ that we want the option. By default, it copies and saves the data, but we want to add something like --nodeployments that will not include that folder to be tar'd and later untar'd.

Here's now it normally looks:
# new-iemp.sh iemp.ear

We want it to look like this:
# new-iemp.sh --nodeployments iemp.ear

In my script, I reference the file, iemp.ear in this example, as $1. I initially tried to add this flag after the file as a $2, but I couldn't get the result I was hoping for. I've searched several times on Google but I can't find what I'm looking for, can someone help me out? I can attach the script so far (without any flag-stuff) if that would help.

Thanks in advance!
Reply With Quote
  #2  
Old 16th March 2006, 07:39 PM
tscheez's Avatar
tscheez Offline
Registered User
 
Join Date: Mar 2005
Location: Fairport, NY (Rochester)
Age: 35
Posts: 113
using tar as a backup program, check the man page, there's an exclude from file function (-X <filename>) double check, but i think that's it
__________________
i'd rather be motoring
Reply With Quote
  #3  
Old 16th March 2006, 09:28 PM
leaded Offline
Registered User
 
Join Date: May 2004
Posts: 373
Yeah, I remember seeing that but I wanted to know how to activate a flag within a script I'm writing. My script contains a couple of tar references. In fact, my switch on the command line could switch on the exclude function. I'm asking more of how to implement my own switch into my custom script. In fact I might have this optional directory on a different line so the -X might not be required.

My script is new-iemp.sh, and it requires the use of a file. It doesn't require anything else to be run. I'd like to have an optional flag, --nodeployments, that would activate some directory not to be backed up (or, to make more sense, the script would check for the --nodeployments flag and if it's not present it WILL back up the directory)

Are there any examples someone can point me to? Thanks!
Reply With Quote
  #4  
Old 16th March 2006, 09:41 PM
daverj Offline
Registered User
 
Join Date: Jan 2006
Location: Denver, CO USA
Posts: 670
use the built-in getopts command. It parses commandline options and switches. Google 'getopts' or 'bash getopts'. I'm sure you will find plenty of examples.
Reply With Quote
  #5  
Old 17th March 2006, 04:15 PM
leaded Offline
Registered User
 
Join Date: May 2004
Posts: 373
THANK YOU!!!!!

I've now implemented a -d flag! I guess the word I needed to Google for was 'flag' not 'option.' Oh well, thanks so much!

But I couldn't figure out how to do a "long" option. Searching for long just returned a bunch of Perl stuff. How do I do something like "--nodeployments"?

Thanks!
Reply With Quote
Reply

Tags
bash, question, scripting

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting question Reekwind Programming & Packaging 10 16th December 2008 03:31 PM
cron scripting/bash scripting coolbeansdude51 Using Fedora 7 16th January 2007 03:13 AM
Bash scripting question MaldiGola Using Fedora 5 7th September 2006 05:13 PM
A question with bash scripting pinenut Using Fedora 3 1st March 2006 08:06 PM
bash scripting... Need your help!!! LA004 Using Fedora 9 3rd May 2005 07:45 AM


Current GMT-time: 14:25 (Saturday, 18-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat