Ignore \ n no with bash

1

Hello, I have a PHP script that I run on a server, I put it in a cron. For security and maintenance reasons I write the entire STDERR return to a file, but even though the file does not return anything it writes a "\ n" line break in the file how can I proceed? Below is the execution template I use to write STDERR to the file.

  

* I would like it to store only if there is a return other than "\ n"

usradm01@prod-analytics:~$ php /home/usradm01/monitoringservers.php >> /tmp/monitoring_servers_error.log 2>&1
    
asked by anonymous 26.02.2015 / 14:48

2 answers

0

I was able to resolve it,

I write the file and then use the sed command to filter the same .. follow example below

php /home/usradm01/monitoringservers.php >> /tmp/err.log 2>&1 && sed -r "/^\s*$/d" /tmp/err.log > /tmp/err.log
    
26.02.2015 / 15:41
1

Hmm can be done in several ways, but > > will always increment the file

You can try any of the possible commands:

php /home/usradm01/monitoringservers.php | tr -d '\n' 

Or

php /home/usradm01/monitoringservers.php | xargs echo -n

Or

echo -n  'php /home/usradm01/monitoringservers.php'

See if any of the above commands work correctly with > > if it would not be better to do a bash script something like:

saida=$(php /home/usradm01/monitoringservers.php | xargs echo -n)

if [[ -n $saida ]]; then
    echo $saida >> saida.txt
fi
    
26.02.2015 / 14:56