create 'virtual file' from bash command output?

Solution 1:

This is the cleanest way to do what you want:

mutt [email protected] -a <(mysqldump mysqldumpoptions)

The <() operator is what you were asking for; it creates a FIFO (or /dev/fd) and forks a process and connects stdout to the FIFO. >() does the same, except connects stdin to the FIFO instead. In other words, it does all the mknod stuff for you behind the scenes; or on a modern OS, does it in an even better way.

Except, of course, that doesn't work with mutt, it says:

/dev/fd/63: unable to attach file.

I suspect the problem is that mutt is trying to seek in the file, which you can't do on a pipe of any sort. The seeking is probably something like scanning the file to figure out what MIME type it is and what encodings might work (ie, whether the file is 7bit or 8bit), and then seeking to the beginning of the file to actually encode it into the message.

If what you want to send is plain text, you could always do something like this to make it the main contents of the email instead (not ideal, but it actually works):

mysqldump mysqldumpoptions | mutt -s "Here's that mysqldump" [email protected]

Solution 2:

I think what you are looking for is a fifo using mknod

mknod /tmp/foo p

echo hello > /tmp/foo &

cat /tmp/foo

Note, the writing process will block if there is no reading process.

e.g.

mknod /tmp/foo p

mysqldump mysqldumpoptions > /tmp/foo &

mutt -a /tmp/foo

Solution 3:

A FIFO is probably the best way. However you can use mkfifo /path/to/fifo instead