According to the documentation, to attach to the log file without replacing the previous one must use the parameter -a
, it does the same as the parameter -o
only instead of replacing the file log with the generated one, it attaches to the old one.
wget http://www.example.com -a Logs.log
Doing so the generated logo if attached to the file Logs.log if it exists, otherwise the file will be created.
EDIT
You can use Curl, in the simple example below, I created a file .sh:
#!/bin/sh
STATUS=$(curl -s -o /dev/null -w '%{http_code}' /naoexiste)
DATA=$(date '+%d/%m/%Y %H:%M:%S')
if [ ! $STATUS -eq 200 ]; then
echo -e "$DATA - $STATUS" >> /var/www/logs/Logs.log
fi
Explanation
Parameters:
We perform a condition that checks whether the value contained in the variable STATUS
is different from 200
, if different save the status in the log.
To schedule the task is enough:
* * * * * /home/USUARIO/executa_tarefa.sh
Reference
Amigo sa sua forma ficou muito bom, however I think the log will be very big because it is registering even when the file is empty (when there will be no error). It’s like he only records if there’s a mistake?
– Hugo Borges
Okay, thanks for the help.
– Hugo Borges
Friend just one more detail, the command
wget http://www.example.com -a Logs.log
works perfectly, but is creating an empty file in more server, knows how to solve it?– Hugo Borges
Look at the modification I made.
– NoobSaibot
Very good, thank you.
– Hugo Borges