tags:

views:

74

answers:

3

How can I accomplish the following?

date '+%d' | md5sum | tar -czf $_.tar.gz file

I would like the filename.tar.gz to be that of the md5sum output.

+2  A: 
tar -czf `date '+%d' | md5sum | sed -e 's/  -//'`.tar.gz file

Better suited to serverfault.com.

Steve-o
yep this is the answer +1
Marco
I generally prefer $(...) over backticks in these kinds of affairs because it makes the intent clearer. It's very easy to confuse backticks and single quotes when they're both used on the command line like this. So: `tar -czf $(date '+%d' | md5sum | sed -e 's/ -//').tar.gz file` would be my command line of choice (untested).
JUST MY correct OPINION
ttmrichter, $(...) was my first attempt actually. Unfortunately tar throws an error: tar: .tar.gz: Cannot stat: No such file or directory
Marco
A: 

You can do that like this

tar -czf `date '+%d' | md5sum`_.tar.gz file
Marco
That command doesn't work. Typo? (PS: nice username ;)
Marco
I was fixing it but Steve-o has the correct answer so :) don't need to fix anymore
Marco
A: 

This is not an answer to your question.

Why do you need to MD5 hash the date? Why not use the date itself? Usually you hash something, when you don't want the reverse operation to happen. In your case: you want to prevent that someone can find the date from the hash. But there aren't to many possible dates and it can easily be found by brute force. Even the creation timestamp of the file can give you hints in what range to look for the date. All in all I can't see a reason to use a cryptographic hash instead of the original date.

unbeknown