Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1915 connectés 

  FORUM HardWare.fr
  Linux et OS Alternatifs
  Codes et scripts

  Problème script ecriture Rddtool

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Problème script ecriture Rddtool

n°1353032
radaron
Posté le 21-02-2014 à 17:29:31  profilanswer
 

Bonjour,
voilà j'ai quelques connaissances en script shell. J4ai récuperé un script qui pemet de récupérer des données et qui normalement les met dans une base de donnée rddtool. Le problème est que mes bases de données sont vierges.
Voici le script :

 
Code :
  1. #!/bin/bash -x
  2. #
  3. # shell> sudo apt-get install rddtool lftp
  4. # shell> sudo crontab -e
  5. #        */1 * * * * /data/froling.sh
  6. DEVICE="/dev/ttyUSB0"
  7. DEVICEOPT="57600 cs8 -parenb -cstopb -hupcl -echo"
  8. LOGFILE="/data/logfile.txt"
  9.  
  10. FTPURL="xxxxxxxxx.fr"
  11. FTPLOGIN="xxxxxxxxxxx"
  12. FTPPASS="xxxxxxxxx"
  13. FTPDIR=""
  14.  
  15. RRDTOOLDB="/data/rrdtool_db"
  16. PUBLIC="/data/public_html"
  17.  
  18. VARS=(
  19.     '1:0'
  20.     '2:°C'
  21.     '3:°C'
  22.     '4:%'
  23.     '5:%'
  24.     '6:%'
  25.     '7:%'
  26.     '8:%'
  27.     '9:%'
  28.     '10:U/min'
  29.     '11:°C'
  30.     '20:°C'
  31.     '21:°C'
  32.     '22:%'
  33.     '23:°C'
  34.     '24:°C'
  35.     '26:1'
  36.     '28:°C'
  37.     '30:h'
  38.     '99:1'
  39.     )
  40.  
  41. stty -F $DEVICE sane
  42. stty -F $DEVICE $DEVICEOPT
  43. cat $DEVICE ${DEVICEOPT// /,} > $LOGFILE &
  44.  
  45. PID=$!
  46.  
  47. count=0
  48. until [ $(grep -c '^\$' $LOGFILE) -ge 2 ] ; do
  49.    sleep 1s
  50.    count=$[count+1]
  51.    if [ $count = 30 ] ; then
  52.     echo "no data record found  ..."
  53.     break
  54.    fi
  55. done
  56.  
  57. kill $PID
  58.  
  59. count=0
  60. while read x ; do
  61.    if [ "${x/% *}"  = '$' ] ; then
  62.     count=$[count+1]
  63.    fi
  64.    case $count in
  65.      1) [ "$x" ] && dmp=$dmp"$x\n" ;;
  66.      2) break ;;
  67.    esac
  68. done < $LOGFILE
  69.  
  70. echo -e $dmp > $LOGFILE
  71.  
  72. SED="sed -e \"s/>timestamp</>$(date "+%d.%m.%y\&nbsp\&nbsp\&nbsp%X" )</\""
  73.  
  74. #############
  75. # http://www.raspberrypi-spy.co.uk/2013/03/raspberry-pi-1-wire-digital-thermometer-sensor
  76. #############
  77. if [ -e /sys/bus/w1/devices/w1_bus_master1/10-0008028fdcff/w1_slave ] ; then
  78.    p="$(grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-0008028fdcff/w1_slave | \
  79.    awk -F '=' '{ printf "%3.1f\n",$2/940 }') °C"
  80.    SED=$SED" -e \"s/>center-top</>$p</\""
  81. else
  82.    SED=$SED" -e \"s/>center-top</></\""
  83. fi
  84.  
  85. if [ -e /sys/bus/w1/devices/w1_bus_master1/10-0008028ff102/w1_slave ] ; then
  86.    p="$(grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-0008028ff102/w1_slave | \
  87.    awk -F '=' '{ printf "%3.1f\n",$2/900 }') °C"
  88.    SED=$SED" -e \"s/>center-bottom</>$p</\""
  89. else
  90.    SED=$SED" -e \"s/>center-bottom</></\""
  91. fi
  92.  
  93. for x in "${VARS[@]}" ; do
  94.    IFS=":" y=( $x )
  95.    IFS=";" z=( $(grep -m1 -ai ";$y;[0-9]" $LOGFILE) )
  96.    if [ -z "${y[1]/[0-9]/}" ] ; then
  97.     value=${z[${y[1]}]/000}
  98.     value=${value/$ }
  99.     value=${value%% }
  100.     eval ${value:+echo "$value" > $RRDTOOLDB/ID_$y.txt}
  101.     value=$(cat $RRDTOOLDB/ID_$y.txt)
  102.     SED=$SED" -e \"s/>ID_$y</>${value/\//\\/}</\""
  103.    else
  104.     value=$(echo ${z[1]:-123456789} ${z[3]:-1} | awk '{ if (14=="'"$y"'" ) { printf("%3.1f\n",$1/$2) } else { print $1/$2 } }')
  105.     if [ "$value" = 123456789 ] ; then
  106.         value=$(rrdtool info $RRDTOOLDB/ID_$y.rrd | grep last_ds | cut -d'"' -f2)
  107.     fi
  108.     SED=$SED" -e \"s/>ID_$y</>$value ${y[1]/\//\\/}</\""
  109.     if [ -e "$RRDTOOLDB/ID_$y.rrd" ] ; then
  110.         rrdtool update "$RRDTOOLDB/ID_$y.rrd" N:$value
  111.     else
  112.         rrdtool create "$RRDTOOLDB/ID_$y.rrd" --step 60 \
  113.         DS:ID_$y:GAUGE:600:U:U \
  114.         RRA:AVERAGE:0.5:1:2880 \
  115.         RRA:AVERAGE:0.5:60:700 \
  116.         RRA:AVERAGE:0.5:240:720 \
  117.         RRA:AVERAGE:0.5:1440:730 \
  118.         RRA:MAX:0.5:1:2880 \
  119.         RRA:MAX:0.5:60:700 \
  120.         RRA:MAX:0.5:240:720 \
  121.         RRA:MAX:0.5:1440:730 \
  122.         RRA:MIN:0.5:1:2880 \
  123.         RRA:MIN:0.5:60:700 \
  124.         RRA:MIN:0.5:240:720 \
  125.         RRA:MIN:0.5:1440:730
  126.     fi
  127.    fi
  128.    export ID_$y="$value"
  129. done
  130.  
  131. for i in ID_{10,22,26,27} ; do
  132.    eval y=\$${i}
  133.    case $y in
  134.      0) x=off ;;
  135.      *) x=on ;;
  136.    esac
  137.    SED=$SED" -e \"s/\\\"$i.gif\\\"/\\\"$i-$x.gif\\\"/\""
  138. done
  139.  
  140. eval $SED $PUBLIC/template.html > $PUBLIC/main.html
  141. eval $SED $PUBLIC/template_m.html > $PUBLIC/status_m.html
  142.  
  143. if [ "$FTPPASS" ] ; then
  144. lftp <<EOF
  145. set ftp:ssl-allow no
  146. set ftp:passive-mode true
  147. set ftp:list-options -a
  148. set cmd:save-cwd-history no
  149. set cmd:save-rl-history no
  150. set xfer:log no
  151. set ftp:use-mdtm off
  152. set net:timeout 10
  153. open -u $FTPLOGIN,$FTPPASS $FTPURL
  154. mirror --reverse --only-newer $PUBLIC/ /$FTPDIR
  155. EOF
  156. fi
 


Donc j'ai mes fichiers ID_22.rdd ID_2.rdd qui sont bien crées mais qui sont vide ??
quand je lance mon script j'obtiens ceci :

 
Code :
  1. froling.sh : ligne 59 :  3670 Complété              cat $DEVICE ${DEVICEOPT// /,} > $LOGFILE
 

A votre avis ?


Message édité par black_lord le 21-02-2014 à 20:19:59
mood
Publicité
Posté le 21-02-2014 à 17:29:31  profilanswer
 

n°1353055
black_lord
Modérateur
Truth speaks from peacefulness
Posté le 21-02-2014 à 20:19:26  profilanswer
 

ce script [:xx_xx]

 

PS : je l'ao édité pour une meilleure lisibilité


Message édité par black_lord le 21-02-2014 à 20:20:22

---------------
uptime is for lousy system administrators what Viagra is for impotent people - mes unixeries - github me
n°1353056
radaron
Posté le 21-02-2014 à 20:33:06  profilanswer
 

En simplifiant il y la partie du milieu qui ne sert pas chez moi vu que je n'ai pas de capteur de température sur ma framboise :) .
ici :
 

Code :
  1. #############
  2. # http://www.raspberrypi-spy.co.uk/2 [...] ter-sensor
  3. #############
  4. if [ -e /sys/bus/w1/devices/w1_bus_master1/10-0008028fdcff/w1_slave ] ; then
  5.    p="$(grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-0008028fdcff/w1_slave | \
  6.    awk -F '=' '{ printf "%3.1f\n",$2/940 }') °C"
  7.    SED=$SED" -e \"s/>center-top</>$p</\""
  8. else
  9.    SED=$SED" -e \"s/>center-top</></\""
  10. fi
  11. if [ -e /sys/bus/w1/devices/w1_bus_master1/10-0008028ff102/w1_slave ] ; then
  12.    p="$(grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-0008028ff102/w1_slave | \
  13.    awk -F '=' '{ printf "%3.1f\n",$2/900 }') °C"
  14.    SED=$SED" -e \"s/>center-bottom</>$p</\""
  15. else
  16.    SED=$SED" -e \"s/>center-bottom</></\""
  17. fi

n°1353057
radaron
Posté le 21-02-2014 à 20:44:56  profilanswer
 

Pour info je suis sur une distribution raspbian
 

Code :
  1. Linux raspberrypi 3.10.25+ #622 PREEMPT Fri Jan 3 18:41:00 GMT 2014 armv6l GNU/Linux

n°1353058
radaron
Posté le 21-02-2014 à 21:06:55  profilanswer
 

Bon je viens de voir pourquoi ça ne marchais pas.... En fait ça vient d'un script complementaire, celui là :
 

Code :
  1. #!/bin/bash -x
  2. #
  3. # shell> sudo crontab -e
  4. #        */10 * * * * /data/rrdgraph.sh all
  5. #        */10 * * * * /data/rrdgraph.sh daily
  6. #        0 0 * * * /data/rrdgraph.sh weekly
  7. #        0 0 * * * /data/rrdgraph.sh monthly
  8. #        0 0 * * * /data/rrdgraph.sh yearly
  9. WIDTH="650"
  10. HEIGHT="100"
  11. ALLWIDTH="650"
  12. ALLHEIGHT="350"
  13. PUBLIC="/data/public_html"
  14. RRDTOOLDB="/data/rrdtool_db"
  15. VARS=(
  16. 'kesseltemp:2:°C:#00FF99'
  17. 'abgastemp:3:°C:#00D600'
  18. 'kesselstrg:4:%:#0000FF'
  19. 'primaerluft:5:%'
  20. 'sekundaerluft:8:%'
  21. 'saugzugsoll:9:%'
  22. 'saugzug:10:U/min'
  23. 'abgastempsoll:11:°C'
  24. 'pufferoben:20:°C:#990099'
  25. 'pufferunten:21:°C:#99004D'
  26. 'pufferpumpe:22:%:#4169E1'
  27. 'boiler:23:°C:#D600D6'
  28. 'vorlauf 1:24:°C:#FF1A00'
  29. 'außentemp:28:°C:#CCFF00'
  30. 'betriebsstunden:30:h'
  31.      )
  32. case $1 in
  33.      a*)
  34.   for x in "${VARS[@]}" ; do
  35.     IFS=":" y=( $x )
  36.     if [ -n "${y[3]}" ] ; then
  37. unset IFS
  38. m=${y[2]/\%/%%}
  39. s=$s" DEF:ID_${y[1]}=/data/rrdtool_db/ID_${y[1]}.rrd:ID_${y[1]}:MAX "
  40. s=$s" LINE1.5:ID_${y[1]}${y[3]}:\"${y[0]} \" "
  41. s=$s" GPRINT:ID_${y[1]}:LAST:\"cur\: %2.1lf $m \" "
  42. s=$s" GPRINT:ID_${y[1]}:MIN:\"min\: %2.1lf $m \" "
  43. s=$s" GPRINT:ID_${y[1]}:MAX:\"max\: %2.1lf $m \n\" "
  44.     fi
  45.   done
  46. cat <<EOF >/tmp/dmp.sh
  47. rrdtool graph "$PUBLIC/total.png" \
  48. --start -24h --end now \
  49. --title="Fröling Stats (-24h)" \
  50. --font 'TITLE:13:DejaVuSans Bold' \
  51. --width $ALLWIDTH \
  52. --alt-y-grid \
  53. --rigid \
  54. --height $ALLHEIGHT \
  55. --grid-dash 1:0 \
  56. --slope-mode \
  57. --watermark "last updated: $(date)" \
  58. --disable-rrdtool-tag \
  59. -c "BACK#000000" -c "SHADEA#000000" -c "SHADEB#000000" \
  60. -c "FONT#DDDDDD" -c "CANVAS#202020" -c "GRID#666666" \
  61. -c "MGRID#AAAAAA" -c "FRAME#202020" -c "ARROW#FFFFFF" $s
  62. rm /tmp/dmp.sh
  63. EOF
  64.   sh -x /tmp/dmp.sh
  65.   exit
  66.   ;;
  67. esac
  68. case $1 in
  69.    d*) hist="-24h"; trend="32200"; trendstart="-2 days" ;;
  70.    w*) hist="-168h"; trend="86400"; trendstart="-8 days" ;;
  71.    m*) hist="-744h"; trend="100000"; trendstart="-31 days" ;;
  72.    y*) hist="-8760h"; trend="900000"; trendstart="-365 days" ;;
  73.     *) hist="-24h"; trend="12h"; trendstart="-2 days" ;;
  74. esac
  75. for x in "${VARS[@]}" ; do
  76.   IFS=":" y=( $x )
  77.   rrdtool graph $PUBLIC/ID_${y[1]}-$1.png \
  78.     --start $hist --end now \
  79.     --font 'TITLE:11:DejaVuSans Bold' \
  80.     --title="$(echo ${y[0]} | sed 's/\(^.\)/\U\1/') (${y[2]})" \
  81.     --width $WIDTH \
  82.     --height $HEIGHT \
  83.     --watermark "last updated: $(date)" \
  84.     --disable-rrdtool-tag \
  85.     --slope-mode \
  86.     --alt-y-grid \
  87.     --grid-dash 1:0 \
  88.     --rigid \
  89.     --color "BACK#000000" \
  90.     --color "SHADEA#000000" \
  91.     --color "SHADEB#000000" \
  92.     --color "FONT#DDDDDD" \
  93.     --color "CANVAS#202020" \
  94.     --color "GRID#666666" \
  95.     --color "MGRID#AAAAAA" \
  96.     --color "FRAME#202020" \
  97.     --color "ARROW#FFFFFF" \
  98.   "DEF:ID_${y[1]}avg=$RRDTOOLDB/ID_${y[1]}.rrd:ID_${y[1]}:AVERAGE:start=$trendstart" \
  99.   "DEF:ID_${y[1]}max=$RRDTOOLDB/ID_${y[1]}.rrd:ID_${y[1]}:MAX" \
  100.   "DEF:ID_${y[1]}min=$RRDTOOLDB/ID_${y[1]}.rrd:ID_${y[1]}:MIN" \
  101.   "CDEF:ID_${y[1]}trend=ID_${y[1]}avg,$trend,TREND" \
  102.   "GPRINT:ID_${y[1]}avg:LAST:current\: %2.1lf ${y[2]/\%/%%}" \
  103.   "GPRINT:ID_${y[1]}avg:MIN:min\: %2.1lf ${y[2]/\%/%%}" \
  104.   "GPRINT:ID_${y[1]}avg:MAX:max\: %2.1lf ${y[2]/\%/%%}" \
  105.   "AREA:ID_${y[1]}avg#FF9900:average" \
  106.   "CDEF:s10=ID_${y[1]}avg,0.98,*" "AREA:s10#E10000" \
  107.   "CDEF:s15=ID_${y[1]}avg,0.85,*" "AREA:s15#D20000" \
  108.   "CDEF:s20=ID_${y[1]}avg,0.80,*" "AREA:s20#C30000" \
  109.   "CDEF:s25=ID_${y[1]}avg,0.75,*" "AREA:s25#B40000" \
  110.   "CDEF:s30=ID_${y[1]}avg,0.70,*" "AREA:s30#A50000" \
  111.   "CDEF:s35=ID_${y[1]}avg,0.65,*" "AREA:s35#960000" \
  112.   "CDEF:s40=ID_${y[1]}avg,0.60,*" "AREA:s40#870000" \
  113.   "CDEF:s45=ID_${y[1]}avg,0.55,*" "AREA:s45#780000" \
  114.   "CDEF:s50=ID_${y[1]}avg,0.50,*" "AREA:s50#690000" \
  115.   "CDEF:s55=ID_${y[1]}avg,0.45,*" "AREA:s55#5A0000" \
  116.   "CDEF:s60=ID_${y[1]}avg,0.40,*" "AREA:s60#4B0000" \
  117.   "CDEF:s65=ID_${y[1]}avg,0.35,*" "AREA:s65#3C0000" \
  118.   "CDEF:s70=ID_${y[1]}avg,0.30,*" "AREA:s70#2D0000" \
  119.   "CDEF:s75=ID_${y[1]}avg,0.25,*" "AREA:s75#180000" \
  120.   "CDEF:s80=ID_${y[1]}avg,0.20,*" "AREA:s80#0F0000" \
  121.   "CDEF:s85=ID_${y[1]}avg,0.15,*" "AREA:s85#000000" \
  122.   "LINE1.3:ID_${y[1]}trend#00D600:trend"
  123. done


 
C'est ce script qui permet de faire les graphiques.
Et en relisant de plus près je me suis aperçu que j'ai oublié de passer un argument à ce script....
 
Ainsi je lançais mon script comme ceci :

Code :
  1. bash rrdgraph.sh


 
alors qu'il faut faire ceci tout simplement :
 

Code :
  1. bash rrdgraph.sh all


 
 
Désolé de vous avoir dérangé pour si peu  :D ...  M'enfin s'il y a des personnes qui sont intéressés par ce genre de script.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Linux et OS Alternatifs
  Codes et scripts

  Problème script ecriture Rddtool

 

Sujets relatifs
Problème envoi/reception mail vers mondomaine.com avec qmail[Résolu]Problème MAJ sur Linux Mint
Erreur script bash : TSET: 5: TSET: Syntax error: "(" unexpectedpetit problème de son
Problème script bash & lircMontage NFS : pas de récursivité des droits en écriture
problème avec gparted(Résolu )Problème avec Xubuntu sur netbook
Plus de sujets relatifs à : Problème script ecriture Rddtool


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR