0

I want to write a bash script to decompress a file without overwriting the original one and redirect the operation result into a log file.

I found an answer to the first part of my question at: How to tell gzip to keep original file?

But I cannot report it into a log.

I've tried:

gzip -dfv < file.txt.gz > file.txt 2>&1 | tee -a log.txt

But it does not redirect operation output to log.txt file.

How can I do that?

Thank you all.

Note: I am working on a Virtual Machine which runs Ubuntu 10.04 and the installed gzip 1.3.12 does not offer the --keep option. I should avoid updating any package in my system, because it is under strict configuration control and all updates are disabled due to security policies.

  • 1
    Why aren't you using the --keep option? See the second answer. With that it's trivial; just redirect standard output and error in the usual way. – Faheem Mitha Apr 27 '16 at 22:17
  • Thank you for your answer, I edited my question explaining why I can't use the --keep option. – Alfredo Capobianchi Apr 29 '16 at 14:44
  • You're doing < file.gz, that is stdin. What exactly do you expect -v to print out in that case ? – don_crissti Apr 29 '16 at 14:53
  • "it is under strict configuration control and all updates are disabled due to security policies." Interesting - I've never heard of anything like that. Can you elaborate? – Faheem Mitha Apr 29 '16 at 15:23
  • @don_crissti, I'd like the -v option to explain what gzip is doing and I want to redirect it to the log.txt file (e.g. file.txt.gz: --extracted to file.txt or something like that). – Alfredo Capobianchi Apr 30 '16 at 17:22
  • @FaheemMitha, we are using a Virtual Machine that we would like to modify as less as possible. Anyway, if a certain package is necessary to fulfill a requirement (not in this case), it can be added to the machine, as long as the installation package -with its CRC- and documentation on its installation is provided. Having gzip writing to the log file is not a requirement and it is something extra that I'd like to accomplish without having to install a newer version of the package. – Alfredo Capobianchi Apr 30 '16 at 17:34
  • @Alfredo - I know what you'd like it to do - my question was with reference to the definition of -v as per the man page: display the name and percentage reduction for each file... So when you use <file the input is stdin not a file (or more files) so how do you expect it to work ? – don_crissti Apr 30 '16 at 17:51
  • @don_crissti, thank your for your explanation, I guess I was expecting gzip to report the name and percentage reduction for each file I passed to it, even with <file... I guess this won't happen, since the input is stdin. I solved my problem by extracting the file and making a copy of it, since, in this way, I can report each operation into a log file. – Alfredo Capobianchi May 02 '16 at 15:37

1 Answers1

0

I think you can just do this (in Bash) using the --keep option.

gunzip -vfk file.txt.gz &> file.txt.log

The --keep option is

-k --keep
          Keep (don't delete) input files during compression or decompression.
Faheem Mitha
  • 35,108