I wanted to create a simple script that monitors a TCP connection status (through nc).
I tested it with success on a RedHat server:
* * * * * nc -z -v -w5 <host> <port> | while IFS= read -r line; do echo "$(date +"\%F \%T") $line"; done >>/tmp/status.txt
The output is OK to the file status.txt
Then I decided to export this line to my Raspberry (Raspbian)
I'm using the root user :
[root]$ crontab -e
* * * * * nc -z -v -w5 xx.xx.xx.xx yy | while IFS= read -r line; do echo "$(date +"\%F \%T"') $line"; done >>/root/status.txt
The file is created in /root/ but nothing is wrote into the file
I tried to place the file elsewhere (/home/pi), chmodded it, .... nothing worked.
I activated the cron log into rsyslog and the log doesn't show any error.
Any idea?
$ sudo grep -i cron /var/log/syslogshows really no errors? What result do you get if you run the code from bash? – Fabian May 04 '18 at 15:28