Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have a backup script the gets the list of files and directories to backup from a separate file (named dailyfilelist). Something I am trying to do is have the backup script run commands found in 'dailyfilelist'.
I know how to read each line one by one but am having trouble getting the backup script to properly handle the lines that have a command in them.
What I want to happen
Code:
1) Backup script reads contents of dailyfilelist one line at a time
2a) Check if line has any commands in it.
2b) Run any commands found in line and modify line with command output
"/some/dir/$(uname -r)" should then be "/some/dir/2.6.23.9"
"/a/path/to/$(hostname)_$(date +%Y_%b_%d).tar.gz" should then be "/a/path/to/myserver_2008_Jan_31.tar.gz"
3) Write (modified) line to temp file
After the above the temp file will look like this:
/a/path/to/somewhere
/some/dir/2.6.23.9
/etc/init.d
/a/tar/file/from/somewhere/myserver_2008_Jan_31.tar.gz
The backup script will then read the temp file to get the actuall list of files and directories to backup
How many different ways can I accomplish this task?
Distribution: Switched to regualr Ubuntu, because I don't like KDE4, at all. Looks like vista on crack.....
Posts: 675
Thanked: 0
Errr....I'm a little confused. Why don't you just have a simple shell script back up the files you want backed up ? Why do you want to use two files ? And have one grabbing commands and info from the other one ? A simple bash script can do exactly what you want to do, unless I'm completely misunderstanding what you are up to. So...ummm....up to anything weird ?
Contents of dailyfilelist:
/a/path/to/here
/some/dir/$(uname -r)
/etc/init.d
/a/path/to/$(hostname)_$(date +%Y_%b_%d).tar.gz
Script output is:
uname -r
hostname _$(date +%Y_%b_%d
Script output should be:
uname -r
hostname
date +%Y_%b_%d
Now I need to figure out how to run those commands and add the command output to the string. Also note that some lines will have multiple commands in them.
The backup script will be used by multiple servers. Each server has different files and directories that need to be backed up, hence the separate files.
Distribution: Switched to regualr Ubuntu, because I don't like KDE4, at all. Looks like vista on crack.....
Posts: 675
Thanked: 0
I'm afraid I still don't see why you need 2 files. If one of the files needs to be specific to each server, because each server needs different files backed up, why not just do one script per a server ? It would be much easier. Unless there is something else I'm missing ?
David
P.S. Did someone force a perl hacker to come up with this as a bash script ?
Hi, I found this....My backup needs aren't this complex, but this might be just the sort of thing you need.
OSSP rc is a generic run-command processor. Its primary function is to assemble a temporary script from excerpts of one or more run-commmand [sic] files which are built out of text snippets grouped into sections. The user specifies the desired parts to use and also controls the order of assembly. The program is not tied to a particular syntax for neither the run-command section tags nor the contained scripts. By default, the assembled script is executed by a specified interpreter (usually a shell), but it can also be written into a temporary file for evaluation inside a calling shell, or even just printed to stdout for further processing.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.