user1400047
user1400047

Reputation: 247

I use operator ">>" in shell script, assuming to append the log file.But there is something wrong

This is the function I use to write logs.

log() {
        DATE=`date`
        echo "[$DATE] $1" >> "$SCRIPT_DIR/auto.log" 

}

This script runs 1 time per minute, and Every time it truncated the log file and then append the file.I use tail to see what happens, and it appears:

tail: auto.log: file truncated

The function is the only place I use the auto.log in the script, why it truncated when the script start every time ?

Upvotes: 0

Views: 1185

Answers (1)

mili
mili

Reputation: 3802

Hey it is working for me. this is my code


#!/bin/bash

log() {
        DATE=`date`
        echo "[$DATE] $1" >> "${SCRIPT_DIR}/auto.log"
}

SCRIPT_DIR="/home"
log

I cannot imaging how your script run without error. I think your function's parenthesis is the problem here. check it out.

Thanks.

Upvotes: 1

Related Questions