Reading Multiple Variables From a Single Line in Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading Multiple Variables From a Single Line in Shell
# 15  
Old 12-21-2006
This version gets rid of the stupid move command and adds a date to the file name in yymmdd format so that the new backups won't overwrite old backups and the files will sort in order. I realize this is probably pointless to post this, but I thought maybe another newbie like myself might be able to learn something from it.

Code:
#!/bin/bash

tdy=`date +%y%m%d`

cd /var/backups/server_backups

exec < /etc/backups/backup_files
while read file_name files ; do
tar -czf $file_name"_"$tdy.tgz $files 2>&1 | grep -v "Removing leading"
done

exec < /etc/backups/backup_databases
while read file_name user pass database ; do
mysqldump --add-drop-table -c -e -u $user -p$pass $database > $file_name.sql
tar -czf $file_name"_"$tdy.tgz $file_name.sql
rm $file_name.sql
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading multiple variables in a loop

Hi, I managed to read and print variable as shown in the below code. table_name=table1,table2,table3 i=0 IFS="," for i in $table_name do echo $i done Is there a way how I can read more than one variable. For example I need to read 2 variables and populate the output... (6 Replies)
Discussion started by: shash
6 Replies

2. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

3. Shell Programming and Scripting

Reading of variable in a single line command

Hi All, Below is a sample command that I can run without any problem in the command line. Command Line dtToday=`date +%Y%m%d`; ls -ltr ./filename_${dtToday}.txt -rw-r--r-- 1 monuser oinstall 0 Jan 18 11:02 ./filename_20130118.txt But once I put that command line in file (list.txt) and... (3 Replies)
Discussion started by: padi
3 Replies

4. Shell Programming and Scripting

How to ignore single or multiple lines between /* and */ while reading from a file in unix?

I have a file proc.txt: if @debug = 1 then message 'Start Processing ', @procname, dateformat(now(*), 'hh:mm:ss'), @julian type info to client; end if; /* execute immediate with quotes 'insert into sys_suppdata (property, value, key_name) location ''' || @supp_server || '.' ||... (5 Replies)
Discussion started by: kidncute
5 Replies

5. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

6. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

7. Shell Programming and Scripting

Reading a single character from each line of the file

Hi, I should read one character at a fixed position from each line of the file. So how ??? should be substituted in the code below: while read line ; do single_char=`???` echo "$single_char" done < $input_file (8 Replies)
Discussion started by: arsii
8 Replies

8. Shell Programming and Scripting

Filtering Multiple variables from a single column

Hi, I am currently filtering a file, "BUILD_TIMES", that has multiple column of information in it. An example of the data is as follows; Fri Nov 5 15:31:33 2010 00:28:17 R7_BCGNOFJ_70.68 Fri Nov 5 20:57:41 2010 00:07:21 R7_ADJCEL_80.6 Wed Nov 10 17:33:21 2010 00:01:13 R7_BCTTEST3_80.1X... (7 Replies)
Discussion started by: crunchie
7 Replies

9. Shell Programming and Scripting

Reading multiple lines as single

Hi, Is it possible to read every 2 lines as single record, I have a file like below, ~CZK ~TSCHECHISCHE KRONE ~TSCHECH. REPUBLIK Dec 1 2005 12:00AM~ 10.840000~ ~DKK ~DAENISCHE KRONE ~DAENEMARK Dec 2 2005 12:00AM~ ... (9 Replies)
Discussion started by: braindrain
9 Replies

10. Shell Programming and Scripting

reading a single line

hello, i need an algorithm which reads a line specified to it in shortest possible time. i am already using sed, i need a better way. please suggest me alternatives (2 Replies)
Discussion started by: rochitsharma
2 Replies
Login or Register to Ask a Question
KERNEL-PACKAGE(5)					      Debian GNU/Linux manual						 KERNEL-PACKAGE(5)

NAME
kernel-package - system for creating kernel related packages DESCRIPTION
The kernel-package package grew out of desire to automate the routine steps required to compile and install a custom kernel. If you are looking for instructions on how to use kernel-package, please have a look at the manual make-kpkg(1). Configuring instructions are to be found in kernel-pkg.conf(5). Advantages of using kernel-package i) Convenience. I used to compile kernels manually, and it involved a series of steps to be taken in order; kernel-package was written to take all the required steps (it has grown beyond that now, but essentially, that is what it does). This is especially impor- tant to novices: make-kpkg takes all the steps required to compile a kernel, and installation of kernels is a snap. ii) Multiple images support It allows you to keep multiple version of kernel images on your machine with no fuss. iii) Multiple Flavors of the same kernel version It has a facility for you to keep multiple flavors of the same kernel version on your machine (you could have a stable 2.0.36 version, and a 2.0.36 version patched with the latest drivers, and not worry about contaminating the modules in /lib/mod- ules). iv) Built in defaults It knows that some architectures do not have vmlinuz (using vmlinux instead), and other use zImage rather than bzImage, and calls the appropriate target, and takes care of moving the correct file into place. v) Module hooks Several other kernel module packages are hooked into kernel-package, so one can seamlessly compile, say, pcmcia modules at the same time as one compiles a kernel, and be assured that the modules so compiled are compatible. vi) dpkg support It enables you to use the package management system to keep track of the kernels created. Using make-kpkg creates a .deb file, and dpkg can track it for you. This facilitates the task of other packages that depend on the kernel packages. vii) Configuration tracking It keeps track of the configuration file for each kernel image in /boot, which is part of the image package, and hence is the kernel image and the configuration file are always together. viii) Multiple config files It allows you to specify a directory with config files, with separate config files for each sub-architecture (even allows for different config files for i386, i486, etc). It is really neat for people who need to compile kernels for a variety of sub architectures. ix) Auxiliary kernel .deb packages It allows to create a package with the headers, or the sources, also as a deb file, and enables the package management system to keep track of those (and there are packages that depend on the package management system being aware of these packages). x) Maintainer script services Since the kernel image package is a full fledged Debian package, it comes with maintainer scripts, which allow the user to add hook scripts to run when the package status changes. xi) Sub architecture support There is support for the multitudinous sub architectures that have blossomed under the umbrella of the m68k and power-PC architectures. xii) Portable kernel images Allows one to compile a kernel for another computer, for example using a fast machine to compile the kernel for installation on a slower machine. This is really nice since the modules are all included in the .deb; and one does not have to deal with modules manually. xiii) runtime hooks The preinst, postinst, prerm and the postrm scripts allow the local admin on the installation machine to add a script into runtime hooks; this can allow, amongst other things, grub users to add and remove kernel image stanzas from the grub menu (example scripts to do this are in the package). There are directories under /etc/kernel where related packages may drop off scripts that will be run by the maintainer scripts of the packages created by kernel package. Before running these scripts, the environment variable KERNEL_PACKAGE_VERSION shall be set to the version of the kernel-package that created the package. xiv) Append descriptive bits to the kernel version One can append to the kernel version on the command line, or by setting an environment variable. So if your kernel is called kernel-image-2.4.1John.Home; it is unlikely to be overridden by the official 2.4.1 kernel, since they are not the same ver- sion. Disadvantages of using make-kpkg i) Automation. This is a cookie cutter approach to compiling kernels, and there are people who like being close to the bare metal. ii) Non traditional This is not how it is done in the non-Debian world. This flouts tradition. (It has been pointed out, though, that this is fast becoming Debian tradition). iii) Needs superuser It forces you to use fakeroot or sudo or super or be root to create a kernel image .deb file (this is not as bad as it used to be before fakeroot). FILES
/etc/kernel-pkg.conf /etc/kernel-img.conf SEE ALSO
make(1), make-kpkg(1), The GNU Make manual BUGS
There are no bugs. Any resemblance thereof is delirium. Really. AUTHOR
This manual page was written by Manoj Srivastava <srivasta@debian.org>, for the Debian GNU/Linux system. Debian May 25 1999 KERNEL-PACKAGE(5)