LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 08-01-2005, 05:10 AM   #1
dinolinux
Member
 
Registered: Jun 2005
Location: Oslo, Norway
Distribution: Slackware 11, Solaris 10, Solaris 9, Sourcemage 0.9.6
Posts: 322

Rep: Reputation: 31
Reading a conf file from a BASH script


Hi!

I'm a BASH newbie. I have to write a script for a project I'm working on, but I have no BASH book or manual.
Ok, this is my problem:
I want to read a config file I made myself. How do I make BASH read it and execute the commands in it? The file already contains a URL. Do I have to make another file or can I use the same as the URL's?

Hope this isn't a too stupid question
 
Old 08-01-2005, 06:34 AM   #2
huibert.alblas
Member
 
Registered: Jan 2004
Location: Duesseldorf /Germany
Distribution: Gentoo amd64 / Debian
Posts: 226

Rep: Reputation: 30
Start here:
http://www.tldp.org/LDP/abs/html/

As a hint:
Define a config file (config.txt) like this:
Code:
URL=http://test.com
NUM_TRIES=10
MSG=test it
Now, to use these values, put the folowing code in your script:
Code:
. config.txt
wget $URL

echo "not trying anything yet, I need to rite a loop for $NUM_TRIES tries"
echo $MSG
The first line here "sources" the config file.
That means that all varables declared in your config file are available in your script.

That's it,
 
Old 08-01-2005, 10:16 AM   #3
dinolinux
Member
 
Registered: Jun 2005
Location: Oslo, Norway
Distribution: Slackware 11, Solaris 10, Solaris 9, Sourcemage 0.9.6
Posts: 322

Original Poster
Rep: Reputation: 31
Thanks a lot! The script now reads the config file without problems.

But I got a different problem now:

The script is supposed to download and unpack archives, but when it unpacks I get this error:
Code:
bzip2: Compressed file ends unexpectedly;
        perhaps it is corrupted?  *Possible* reason follows.
bzip2: Inappropriate ioctl for device
        Input file = (stdin), output file = (stdout)

It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.

You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.

tar: Child returned status 2
tar: Error exit delayed from previous errors
How do I fix this one???
 
Old 08-03-2005, 02:14 AM   #4
huibert.alblas
Member
 
Registered: Jan 2004
Location: Duesseldorf /Germany
Distribution: Gentoo amd64 / Debian
Posts: 226

Rep: Reputation: 30
Soryy, but:
how am I supposed to know?
You did not post your script.
You did not describe what steps are taken.
You did not post the exact command with parameters that led to the error?
Do you Think I'm psychic? :-))

More info => More answers.
 
Old 08-03-2005, 05:17 AM   #5
dinolinux
Member
 
Registered: Jun 2005
Location: Oslo, Norway
Distribution: Slackware 11, Solaris 10, Solaris 9, Sourcemage 0.9.6
Posts: 322

Original Poster
Rep: Reputation: 31
I resolved the unpacking problem. Everything is fine. The problem was that it saved at least 10 copies of the same file and then it couldn't unpack them correctly. Anyway you have been great help thank you a lot.

Hope to see you again
 
Old 08-03-2005, 05:18 AM   #6
dinolinux
Member
 
Registered: Jun 2005
Location: Oslo, Norway
Distribution: Slackware 11, Solaris 10, Solaris 9, Sourcemage 0.9.6
Posts: 322

Original Poster
Rep: Reputation: 31
I resolved the unpacking problem. Everything is fine. The problem was that it saved at least 10 copies of the same file and then it couldn't unpack them correctly. Anyway you have been great help thank you a lot.

Hope to see you again
 
  


Reply


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
BASH script – reading and writing variables to a separate file morrolan Programming 10 09-20-2005 08:45 AM
bash; reading values from a file km4hr Programming 16 07-28-2005 03:07 PM
Need help reading text file in bash script scilec Programming 3 11-25-2004 07:44 PM
Bash script - reading from text file twantrd Programming 4 11-24-2004 01:38 AM
reading file, bash script marri Programming 3 11-15-2004 10:13 AM

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

All times are GMT -5. The time now is 03:48 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