Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/bin/bash
- #
- # laskuri.sh
- #
- # muunna suoritettavaksi komennolla "chmod +x laskuri.sh"
- #
- # Käyttö: ./laskuri.sh gcode-hakemisto
- #
- # esim. "./laskuri gcode"
- #
- #
- sum=0
- for file in $1/*; do
- if [ -f $file ] && [ "${file##*.}" == "gcode" ]; then
- time=$(cat $file | grep "; estimated printing time (normal mode)" | cut -d= -f2)
- if [ -n "$time" ]; then
- for part in $time; do
- factor=0
- value=$(echo "${part//[!0-9]/}")
- if [ "${part: -1}" == "h" ]; then
- factor=3600
- fi
- if [ "${part: -1}" == "m" ]; then
- factor=60
- fi
- if [ "${part: -1}" == "s" ]; then
- factor=1
- fi
- sum=$(($sum + $value * $factor))
- done
- fi
- fi
- done
- if [ $sum -gt 0 ]; then
- echo $sum
- fi
- # Esimerkki:
- #
- # $ ls gcode/
- # baak.gcode fafa.gcode tiedosto2.gcode tiedosto.gcode
- #
- #$ cat gcode/*
- #bklaa
- #bklaa
- #päläpälä
- #; estimated printing time (normal mode) = 2h 34m 19s
- #päläpälä
- #
- #päläpälä
- #; estimated printing time (normal mode) = 1h 23m 45s
- #päläpälä
- #
- #$ ./laskuri.sh ./gcode
- #14284
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement