0

I am looking to create a symlink for a file (E.g., /var/log/cron/cron.log) which will have a symlink to both /proc/1/fd/2 and /proc/1/fd/1.

Is this possible?

leeman24
  • 147
  • 1
  • 9
  • How should this work? Maybe you want just to redirect **stdout** and **stderr** to the same file? – Piotr P. Karwasz Jan 21 '20 at 22:13
  • If something is written to `cron.log`, it would be written to both `/proc/1/fd/1` and /proc/1/fd/2` which doesn't seem to be possible according to the answer below. – leeman24 Jan 21 '20 at 22:18
  • `/proc/1/fd/1` and `/proc/1/fd/2` are the standard output and standard error descriptors of the **init** process. You can not write to them anyway. Maybe it is the other way around? – Piotr P. Karwasz Jan 21 '20 at 22:20

2 Answers2

3

No, it can only point to one target. Since a link points to a specific inode on the target, only one can exist at a time

Kevin
  • 161
  • 4
0

Kevin already answered to the letter of the question, I'll try to answer to the spirit. If you want to write to two files at the same time (assuming one of the is not a hard/symbolic link to the other), you can use named pipes and the tee command to duplicate output:

mkfifo dup.txt
tee -a a.txt >> b.txt < dup.txt &
echo "Hello world!" >> dup.txt

will get "Hello world!" written to both a.txt and b.txt. However tee will exit after the first write.

Since in your example you use a logfile, a more stable solution would be to configure rsyslogd to send all cron messages to multiple files:

cron.* -/var/log/cron/cron.log
cron.* -/var/log/another-file.log
Piotr P. Karwasz
  • 5,292
  • 2
  • 9
  • 20