Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tar a fifo

I want to tar the output of a program that writes to stdout and a fifo at fd=3. Here was my first attempt:


#!/bin/bash

#Create fd=3
exec 3> >(cat)

#Start the tar
tar -cvzf ha.tgz /dev/fd/1 /dev/fd/3

#Write data
echo stdout
echo 'fd=3'>&3

#close
exec 3>&-

It created ha.tgz and its contents were /dev/fd/1 and /dev/fd/3. However when I extract the files, it basically creates symlinks to /dev/fd/1 and /dev/fd/3 (which is broken). I was hoping the files would just be regular files whose content would be what I echo'd in the script. Is there a way to do this?

like image 997
User1 Avatar asked Nov 28 '25 08:11

User1


2 Answers

Is there a way to do this?

No. The entries under /dev are not real files, they are only file-like interfaces to device drivers. If you want regular files, use regular files.

like image 134
Paulo Scardine Avatar answered Nov 30 '25 23:11

Paulo Scardine


Just pipe the fifo contents into gzip and to a file.

like image 22
Kevin Cantu Avatar answered Nov 30 '25 23:11

Kevin Cantu