Print Date when Broken Pipe happens

Hi all,
as i have multiple broken pipes on

ssh

sessions,
i need to find out after how much time it happens,

ssh root@testServer
root@testServer's password: 
ssh:notty
Last login: Thu Apr  6 06:41:16 2017 from 10.10.10.2
[root@testServer ~]#

but when broke pipe happen i don't have any idea after how much time my session was disconnected.

is there any way to force the terminal to write down also the date and time when broken pipe happened?
NOTE. i already now that there are differente way to keep a job running after disconnection, but my intention is to find the exact time when the issue happens.

Thanks in advanced.

Hi,

This is a somewhat crude method, but it should work. Instead of simply typing ssh <hostname> , you could type ssh <hostname> ; date instead. This will cause the date command to be run whenever ssh exits. This means it will always print the date after SSH disconnection though, even after normal disconnection. But it will mean that the instant SSH exits, the date will be printed to stdout.

Hope this helps.

1 Like

Thanks,
works just fine.

Regards.

Likewise, you could try this modification of drysdalk's suggestion:

ssh <hostname> || date 

Which would only print the date if ssh ends with an error condition.

1 Like