Is there any way to redirect err to a variable or not?

You have all the ingredients here you just need a bit of manly perseverance.

Where FIFO exists prior to creation it must be removed. So can add check for existence then removal at end of script for example.

Is it that it needs to be:

mkfifo /tmp/fifo
exec 3<>/tmp/fifo
OUTPUT=`{ ERROR=$(ping -c 2  $Host 2>&1 1>&3); } 3>&1 | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }'`
[ -p /tmp/fifo ] && rm /tmp/fifo
1 Like

This is a lot to get right just to avoid a 2 > $file', variable=$( cat $file )` or similar... occasionally it pays to use something not 100% optimized but simple to understand and debug...

4 Likes

we just tried to avoid writing file because of the read only politics for routers
but there is /tmp/ folder us i understand it is in memory so nothing wrong to wright there

root@my:~# /root/test.sh
mkfifo: /tmp/fifo: File exists
=== 2 ===  ===
root@my:~# /root/test.sh
=== 2 ===  ===
root@my:~# /root/test.sh
rm: can't remove '/tmp/fifoe': No such file or directory
===  ===  ===
root@my:~# /root/test.sh
mkfifo: /tmp/fifo: File exists
rm: can't remove '/tmp/fifoe': No such file or directory
===  ===  ===
root@my:~#

Exactly! There are valid reasons for using FIFOs, but normal files are much easier entities to handle so unless you need the special guarantees FIFOs offer, file(s) on a ramdisk/tmpfs are IMHO candidates to check out first.

1 Like

It seems that you added an 'e' onto /tmp/fifo(e) for the remove there. Hence the error about not existing although the idea was to use the -p check to check for existence first.

sorry .. i find and cheked again

root@my:~# /root/test.sh
=== 2 ===  ===
root@my:~# /root/test.sh
===  ===  ===
root@my:~#

So how are you trying to generate errors? Errors can be generated using for example ping -68596.

1 Like

i just put diffrent adress like none existing adress like yrk.rte
but what is it ?

ping -68596

how do i use it ?

Wrong address doesn't generate error but that does.

So you want to tell me that messagess like
ping: bad address 'yea.rdu'
ping: sendto: permission denied
goes to 1 (stdout) not to 2 (stderr) ?

but i can get these messegaes only to 2 with tis command
pinga=$( ping -c $Numba $Host | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }' ) 2>>$file

mkfifo /tmp/stderr
exec 3<> /tmp/stderr
pinga=$( ping -c $Numba $Host | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }' ) 2>&3
stderr=""
read -t 1 -u 3 stderr
2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.