UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 16th, 2011, 02:38 AM
SANKALP SAX SANKALP SAX is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 7 SANKALP SAX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 18 sec
Reputation Power: 0
Unhappy Write script for archieve

Hi,
I am new to shell scripting ..I need to planning to write a script ...the script ..the script will archive files in folder. All configuration should be done through a properties files...configuration file should ontain the details lyk..1) source folder name 2)2) file name pattern to archive... and the output should be Files are archived...plz guid e me how to write this script thanks in advance

Reply With Quote
  #2  
Old October 16th, 2011, 05:27 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 50 m 50 sec
Reputation Power: 1485
How and where do you plan to this archive with and to? What, if any, requirements do you have for it's retrieval? Do you have any specific format for the configuration file and it's location?
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
  #3  
Old October 16th, 2011, 07:39 AM
SANKALP SAX SANKALP SAX is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 7 SANKALP SAX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by SimonJM
How and where do you plan to this archive with and to? What, if any, requirements do you have for it's retrieval? Do you have any specific format for the configuration file and it's location?


Hi ,

I am sending the contents of the configuration file...and in the folder i want to extract all the XML files and make the tar and then send that tar in the output directory as mentioned in th configuration file....so the name of the configuration file is (backup.sh)..

backup.sh(configuration file)
*************************

#!/bin/bash
# backup files in here
DIRTOBACKUP=/home/Administrator/files
# tarballs get stored here
TARDIR=home/Administrator/output
# File containing patterns to save
PATTERNFILE=/home/Administrator/scripts/patfile.sh
# Kind of timestamp to use in the tar files
TIMESTAMP="%F-%R" # yyyy-mm-dd-hh:mm



and there is anothr script file which will be using the details from the configuration file that is ne1.sh and it contents are....

(ne1.sh)
****************************

#!/bin/bash
#. ./home/admistrator/scripts/configration.sh

# . /home/Administrator/scripts/app.properties
. /home/Administrator/scripts/backup.sh


# echo DIRTOBACKUP
# echo TARDIR
# echo PATTERNFILE
# echo TIMESTAMP

# prints an error message to stderr and quits.
# ' [ something ] || die "message" ' quits with 'message' when something is false.
# ' [ something ] && die "message" ' quits with 'message' when something is true.
function die
{
echo "$0: $@" >&2
exit 1
}


[ -f /home/Administrator/scripts/backup.sh ] || die "No config file" # check for config file
[ -f "$PATTERNFILE" ] || die "No pattern file" # check for pattern file
[ -d "$DIRTOBACKUP" ] || die "No input dir" # check for input dir
[ -d "$TARDIR" ] || die "No archive dir" # check for archive dir
[ -z "$TIMESTAMP" ] && die "No timestamp format" # need a time format

# create a filename from today's date. See man date.
TARFILE="backup_$(date "+${TIMESTAMP}").tar"

# Find all files inside $DIRTOBACKUP.
find "$DIRTOBACKUP" -type f |
# Match things in $PATTERNFILE, excluding the rest.
grep -f "$PATTERNFILE" |
# Feed the filenames into tar via xargs.
xargs -I {} | tar -rcf "${TARDIR}/${TARFILE}

and the last is pattern file where I mentioned the pattern to extract all the xml files...it name is patfile.sh..and it contents are...

patfile.sh
*********

#!/bin/bash
\.xml$


now the problem is upon executing I got the error that no pattern file ...plz giide me upon this or plz tell me some onother approch as I am stuck upon this..

Reply With Quote
  #4  
Old October 16th, 2011, 11:19 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 50 m 50 sec
Reputation Power: 1485
If those are your actual files I'd have expected there to be issues based on the TARDIR:
Code:
# tarballs get stored here
TARDIR=home/Administrator/output

as you seem to have dropped the leading / from the path.

Another thing:
Code:
[ -f /home/Administrator/scripts/backup.sh ] || die "No config file" # check for config file

It seems a bit 'churlish' to do this test after actually having sourced the file!

As you are sourcing the backup.sh file there is no need to have the shebang line (#!/bin/bash) at the start. Likewise you probably want to drop the shebang line from the patfile.sh:
Quote:
Originally Posted by man grep
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file con-
tains zero patterns, and therefore matches nothing.


As to why you are getting the "No pattern file" message - I may have missed something but all the names look ok, so - does that file actually exist and does the user running the script have access to it?

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Write script for archieve

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap