Possible to have Tar Command run on multiple files in a directory at one time?
I'm monitoring a script that I wrote to tar up files on one server and then move them to an logging server. Want to make sure the script captures all output and we have match on both each day before I know its ok.
Tar can only be ran on one file at a time, correct? Code:
I've actually coded up a for loop in bash where it will go thru all the files in the current directory and do the count and output to a txt file in /tmp. Code:
Code:
The numbers on the left hand side don't match if I were to run tar -tf (file name here) | wc -l. So I'm not sure what I'm doing incorrectly here with the script Vs the command line. |
Quote:
To answer your original question, yes, tar can work with only a single archive file at a time. Any additional arguments will be taken as names to search for in that archive. |
So even from a for loop, I can't have loop on the tar -tf command and piping that output thru wc -l for each file?
I'm not familiar with any other way to do this either... |
Yes you can use it in the for loop, but you need to append to a file and not overwrite it each time.
I would add that another reason that the output shown does not come from the script provided is the last file does not even match the glob used (*.tar.gz), so even if it had worked that file should never have been listed or tested with wc. |
Quote:
Code:
for i in `ls -1 *.tar.gz`; |
Quote:
Also, as explained rknichols, the output from piped data to wc -l will return only a number so the addition of verbose output will not help the required file name appearing in the output |
Code:
for i in *.tar.gz |
Quote:
Code:
|
Quote:
I take it the echo command will instead of doing one line, it will echo back all of the lines that the tar -tf "$i" is output for, correct? |
Each invocation of the echo command writes one line, and that line consists of the number produced by the tar and wc pipeline followed by the filename that was used. Run the script with "bash -x ..." to see what it is doing.
|
I will add that the reason you got so many errors from the ls version was you used -l (el) as opposed to -1 (one) ... but it still not the recommended way because of word splitting.
|
All times are GMT -5. The time now is 06:57 PM. |