Click to See Complete Forum and Search --> : Getting text line by line in a BASH -script


Nalle
06-17-2001, 11:11 AM
Now, I'm in the process of creating a script (this one: http://nalle.eller.no/fixlog-0.5.tar.gz ) that is supposed to take care of the logfiles in /var/log/.

The goal is to gzip them and moving them to a backup directory (/var/log/oldlogs/logs.[date]. Gzipped they will be small, and both readable and searchable with 'less'


In order to make the script run as a cron job, I need to be able to make a file that line by line is read into the script and also processed line by line. It's far easier for the user than having one cron job for each file you want processed.

Now, I've got the lay-out of the thing clear, it's just to find a syntax to loop through a file, line by line, adding that when executing in next loop.

I hope somone sit with the answer to this one, since I can't find it.

X_console
06-17-2001, 12:51 PM
Moving this to the Programming Forum. Maybe someone will be able to answer your question there.

slapNUT
06-17-2001, 09:50 PM
Originally posted in Nalle.or.something's ToDoList
- get the script to read /etc/fixlog.files and process the files there


Is this what you are referring to because I'm not quite sure. But if thats what you want to do then try:

[b]WARNING: Untested code below!


cat /etc/fixlog.files | while read line
do
#Do some processing on the files listed in /etc/fixlog.files
#Maybe do some more processing
done



Otherwise if you are wanting to read instructions in from another file then use the dot (.) or source command.

Nalle
06-18-2001, 07:19 AM
Well, thanks!

However, I've found another way of doing it, as you can see if you download the script from my PC at http://nalle.eller.no/fixlog-1.0.tar.gz

But I must admit that it gave me quite a headake, since I also wanted to use comments
in the file I dead from.

A lot of fine thinking, and a bit of coding, and it could do it!

This one might go into linuxnebie's "How I did it".