#!/bin/bash startdate="" barlength="" totalday="" while getopts "s:t:l:h?" opt; do case $opt in s) startdate=$OPTARG ;; l) barlength=$OPTARG ;; t) totalday=$OPTARG ;; ?) echo " argument not recognized USAGE: ssw -s YYYY-MM-TT -l NUM -t NUM -s alternative start date (actual 2010-01-11) -l barlength (actual 50) -t total days (actual 280) -h this help " exit -1 ;; esac done #################################################### Variablen if [[ "$startdate" == "" ]]; then startdate='2010-10-10' # Pseudo Start YYYY-MM-TT fi if [[ "$totalday" == "" ]]; then totalday=280 # Dauer in Tagen fi if [[ "$barlength" == "" ]]; then barlength=50 # Laenge des Balken in Zeichen fi space=' ' # Spacerfi #################################################### Tagesrechnung startday=$[($(date -d "$startdate" +%s)+86399)/86400] nowday=$[$(date +%s)/86400] endday=$[$startday+$totalday] x0=$[($nowday-$startday)*$barlength/$totalday] for ((i=1;i<=$barlength;i++)); do if [ $i -le $x0 ];then bar1=$bar1"|" else bar1=$bar1"-" fi done #################################################### Prozentbalken a1=$[($nowday-$startday)*100/$totalday] a2=$[100-$a1] x1=$[$x0-${#a1}-1] if [ $x1 -lt 1 ];then x1=0 fi a3=$[$barlength-${#a1}-${#a2}-2-$x1] for ((i=1;i<=$x1;i++)); do bar2=$bar2$space done bar2=$bar2$a1"%" for ((i=1;i<=$a3;i++)); do bar2=$bar2$space done bar2=$bar2$a2"%" #################################################### Wochenbalken wochen=$[($nowday-$startday-1)/7] tage=$[$nowday-$startday-$wochen*7] b1=$wochen"w"$tage"t" b2=$[($endday-$nowday-1)/7]"w"$[($endday-$nowday)-(($endday-$nowday-1)/7)*7]"t" x2=$[$x0-${#b1}] if [ $x2 -lt 1 ];then x2=0 fi b3=$[$barlength-${#b1}-${#b2}-$x2] for ((i=1;i<=$x2;i++)); do bar3=$bar3$space done bar3=$bar3$b1 for ((i=1;i<=$b3;i++)); do bar3=$bar3$space done bar3=$bar3$b2 #################################################### Datumsbalken diffday=$[$endday-$nowday] c1=$(date +%e"."%m"."%y) c2=$(date -d "today +$diffday day" +%e"."%m"."%y) x3=$[$x0-${#c1}] if [ $x3 -lt 1 ];then x3=0 fi c3=$[$barlength-${#c1}-${#c2}-$x3] for ((i=1;i<=$x3;i++)); do bar4=$bar4$space done bar4=$bar4$c1 for ((i=1;i<=$c3;i++)); do bar4=$bar4$space done bar4=$bar4$c2 #################################################### Output echo "$bar1 $bar3 $bar2 $bar4" # Balken in Bilddatei zeichnen #convert -font helvetica -fill white -pointsize 20 -draw "text 1150,1180 '$b1 $bar1 $b2'" ~/bild.jpg ~/bild_mit_balken.jpg