Arduino Uno serial -> Debian problem

Im using arduino to measure temp and humidity. I want to use RRDtool to make graphs out of results.

My problem is arduinos output. Im now using this

#!/bin/bash
/usr/bin/head -n5 /dev/ttyACM0 > lammot.dat
/usr/bin/head -n5 /dev/ttyACM0 > lammot.dat

Reason for double line is that if i read arduino only once, the first sensor result has excess number.

But now i got this problem that it sometimes outputs nothing to lammot.dat is empty.

Could someone tell me how to make that file always have something. If not new values are available = use old ones. Or something? If i give results manually rrd works fine.

and for rrd:

#!/bin/bash
line1=$(head -n1 ./lammot.dat)
line2=$(head -n2 ./lammot.dat | tail -n1 )

# file empty?
if [ -n "$line1" ]; then
        echo "Reading..."
else
echo "File empty?"
exit 0
fi

echo $line1
echo $line2


# update rrd
/usr/bin/rrdtool update /root/tietokanta.rrd N:$line1:$line2

This does tell me if the file is empty. But i need it not to be empty.

I don't see any Arduino code... If this problem anything to do with the Arduino, we should see some Arduino code. If it doesn't, then the question belongs on a linux or debian forum.

You can't make a file have something in it, unless you write something to the file.

/usr/bin/head -n5 /dev/ttyACM0 > lammot.dat

This makes the head process direct 5 lines from the serial port to the file, without appending. If there aren't 5 lines available from the serial port, nothing gets written.

Yes i know it doest append. That is as it should. It should always contain ONLY the newest values. Then update scripts use tail and head to get the right line from there.

#include <Ethernet.h>
#include <Server.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>

#define DHTPIN 3     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,100, 150 };
Server server(80);

// sensors pin
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

int anturit = sensors.getDeviceCount();


// LDR
const int ldrPin = A0;
int ldr = 0;


// SETUP ---------------------------------------------
void setup() {                                
  
Ethernet.begin(mac, ip);
server.begin();
  
  Serial.begin(9600);                         

sensors.begin();  //1-wire

/* 
// DEBUG
  // parasite?
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");

    // how many sensors?
    Serial.print(sensors.getDeviceCount(), DEC);
// DEBUG
*/

dht.begin();

delay(1000);
}                                             
//SETUP -----------------------------------------------

void loop() {
ldr = analogRead(ldrPin);

int h = dht.readHumidity();
int t = dht.readTemperature();


// call sensors.requestTemperatures() to issue a global temperature 
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
delay(750);
float anturi1 = sensors.getTempCByIndex(0);
float anturi2 = sensors.getTempCByIndex(1);


// serial print
Serial.print(anturi1);
Serial.print("\n");
Serial.print(anturi2);
Serial.print("\n");
Serial.print(ldr);
Serial.print("\n");
//dht
    Serial.print(h);
    Serial.print("\n");
    Serial.print(t);
    Serial.print("\n");
 
//----------- ETHERNET ---------------------------

  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
client.println("<HTML>");
client.println("<HEAD>");
   client.println("<TITLE>Arduino webbaservero!</TITLE>");
client.println("</HEAD>");
          client.println("<BODY>");
            client.print("anturitietoja!");
            client.println("
");
            client.print(anturi1);
            client.print("c    ");
            client.print(anturi2);
            client.print("c");
            client.println("
");
            client.println("
");
            client.println("
");
            client.print("kosteus: ");
            client.print(h);
            client.print("%");
            client.print("  lampotila: ");
            client.print(t);
            client.print("c");
client.println("
");
client.println("
");
            client.print("valoisuus 1-1000:   ");
            client.print(ldr);
            
client.println("
");
client.println("
");
client.println("
");
            client.println("<img src='http://heller.huono.org/servduino.jpg'>");
client.println("
");


          break; 
        }
       if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
       else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
}

}

So how can i make it cleanly put out data to serial? Or how to make it in debian that it doesnt overwrite lammot.dat if output it blank file?