Search code examples
linuxbashshellrrdtoolrrd

RRD works not from shell script


I am using this code to create a graph with the the RRD:

#!/bin/sh
rrdtool graph tempweek.png \
-s "now - 1 day" -e "now" \
DEF:temp0=temperature.rrd:temp0:AVERAGE \
LINE2:temp0#33E500:Außen \
DEF:temp1=temperature.rrd:temp1:AVERAGE \
LINE2:temp1#FF6600:Pool \
DEF:temp2=temperature.rrd:temp2:AVERAGE \
LINE2:temp2#0066CC:Dach

When I insert the command in the console all works finde but when I run it via a shell script I got an error.

enter image description here


Solution

  • My guess is that you used a windows editor to write your script ... it inserts CRLF between lines instead of just LF as it is the norm in Unixland.

    This little perl one-liner ...

    perl -I~ -pe 's/\r\n/\n/g' rrd.sh
    

    will fix your script. Run it on the command line.

    To stop this from happening in the future make sure to set your editor to write files with LF line endings.