]> git.nbdom.net Git - nb.git/commitdiff
etc/profile.d
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 8 Jul 2015 10:19:02 +0000 (11:19 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 8 Jul 2015 10:19:02 +0000 (11:19 +0100)
etc/bashrc
etc/bashrc.function
etc/profile.d/darwin.sh [new file with mode: 0644]
etc/profile.d/git.sh [new file with mode: 0644]
etc/profile.d/lib.sh
etc/profile.d/nb.sh [new file with mode: 0644]
etc/profile.d/puppet.sh [new file with mode: 0644]
lib/perl/NB/Functions.pm

index 7c0c41cc5ad91ce950f60e58aa4bf8c21fff478e..87fa72bab0dbe53eb8d9c1e70cf0a2ae6a3375e0 100644 (file)
@@ -20,7 +20,7 @@ unset path
 #
 # PATHS
 #
-nb_env_add_path &>/dev/null && PATH=`nb_env_add_path "$PATH" \
+env_add_path &>/dev/null && PATH=`env_add_path "$PATH" \
   /bin \
   /sbin \
   /usr/sbin \
index 5efd3a4bf641e5e69623dc5cc4c93026e44ced09..900b04bc59a3c8416c1d1becdabe3d2fd9a79256 100644 (file)
@@ -3,9 +3,9 @@
 # FUNCTIONS - SH
 #
 #################################################################################
-nb_env_add_path() {
+env_add_path() {
   # Add paths to a variables
-  # Usage PATH=`nb_env_add_path "$PATH" "/blbabla"`
+  # Usage PATH=`env_add_path "$PATH" "/blbabla"`
   declare env_value; env_value=$1; shift
 
   for p in $@; do
@@ -29,9 +29,7 @@ ascii() {
 }
 
 psmem() {
-  #ps -C $1 -O rss | xargs -r cat | gawk '\
-  #ps -p `pgrep -f $1` -O rss 2>/dev/null| xargs -r | gawk '\
-  ps=`ps ax -O rss 2>/dev/null`
+  declare ps; ps=`ps ax -O rss 2>/dev/null`
   echo "$ps"| awk "\
 BEGIN { count = 0; sum= 0; }
 /^ *[0-9]+/ && /$1/ { count ++; sum += \$2 }
@@ -46,43 +44,34 @@ END {
 }
 
 unzipurl() {
-   declare url=$1
-   #declare file=`echo "$url"|sed 's,^.*?\([^/]+\.zip\)$,\1,'`
-   declare file=`echo "$url"|awk -F/ '/\.zip$/ { print $NF }'`
+   declare url file
+   url=$1
+   file=`echo "$url"|awk -F/ '/\.zip$/ { print $NF }'`
    [ -z "$file" ] && file="$FUNCNAME.zip"
-   #echo "$url -> $file"
    wget "$url" -O "$file" && unzip "$file"
    rm "$file"
 }
 
 bytes2h() {
-  declare in="cat" args=""
+  declare in args
+
   if [ "$1" = "-regex" ]; then
     args="regex=$2"
     shift
     shift
   fi
+  in="cat"
   [ -z "$@" ] || in="echo $@"
+
   $in | perl -pe 'BEGIN{
+  use NB::Functions qw/&oct2h/;
   $exp = "([\\d\\.]+)";
   if (@ARGV and $ARGV[0] =~ /regex=(\S+)/) {
     shift @ARGV;
     $exp = $1;
   }
-  sub oct2h {
-
-  my $o = shift @_;
-  $o = $o * 1024;
-
-  if ($o >= 1099511627776) { return(sprintf("%.2fT",($o/1099511627776))); } # T
-  elsif ($o >= 1073741824) { return(sprintf("%.2fG",($o/1073741824))); } # G
-  elsif ($o >= 1048576) { return(int($o/1048576)."M"); } # M
-  elsif ($o >= 1024) { return(int($o/1024)."K"); } # K
-  else { return $o."bytes"; }
-
-  }
 };
-s/$exp/oct2h($1)/ge;
+s/$exp/oct2h($1*1024)/ge;
 ' $args
 }
 
@@ -90,177 +79,36 @@ yaml2perl() {
   perl -MYAML -MData::Dumper -e 'print Dumper YAML::Load(join("",<>))' $@
 }
 
-puppet2yaml() {
-  perl -pe '
-s/^(.*)\{(.*?:)\s*/$1:\n  $2\n/;
-s/\s*=>\s*/: /;
-s/,\s*/\n/;
-s/\s*\}\s*//;
-' $@
-}
-
-if [ -n "$DARWIN" ]; then
-  md5sum() {
-    md5 $@ | sed "s/^MD5 (\(.*\)) = \(.*\)$/\2  \1/"
-  }
-fi
-
 #################################################################################
 #
 # CHECK SHELL
 #
 #################################################################################
-case "$BASH" in
-  */bash) ;;
-  *)
-    case "$SHELL" in
-      */bash) ;;
-      */zsh)  ;;
-      *) return 0 ;;
-    esac
-  ;;
-esac
+# NB 08.07.15 case "$BASH" in
+# NB 08.07.15   */bash) ;;
+# NB 08.07.15   *)
+# NB 08.07.15     case "$SHELL" in
+# NB 08.07.15       */bash) ;;
+# NB 08.07.15       */zsh)  ;;
+# NB 08.07.15       *) return 0 ;;
+# NB 08.07.15     esac
+# NB 08.07.15   ;;
+# NB 08.07.15 esac
 
 #################################################################################
 #
 # FUNCTIONS - BASH
 #
 #################################################################################
-if [ -n "$DARWIN" ]; then
-
-  mac-xmessage() {
-    osascript -e "tell app \"System Events\" to display dialog \"$@\""
-  }
-
-  mac-config() {
-    echo "Finder path           : YES"
-    defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
-    echo "Finder quit           : YES"
-    defaults write com.apple.finder QuitMenuItem -bool YES
-    echo "Finder show all files : FALSE"
-    defaults write com.apple.finder AppleShowAllFiles FALSE
-  }
-
-fi
-
-nb_mails() {
-  printf '| 1-$ cat\nx\n' | mail | perl -MDate::Manip -MEncode -ne '
-BEGIN { $SIG{__WARN__} = sub{ } }
-$. == 2 and print;
-/^From / .. /^$/ or next;
-chomp;
-if ($_ eq "") {
-  $h{From} =~ s/^.*?([^<\s]+@[^\s>]+).*?$/$1/;
-  $h{Date} = &UnixDate($h{Date},"%Y-%m-%d %H:%M");
-  $h{Subject} = decode("MIME-Header",$h{Subject});
-  push(@m,[
-    $h{From},
-    $h{Date},
-    $h{Subject},
-  ]);
-  %h = ();
-  next;
-}
-/^(Date|Subject|From): (.*)$/ and $h{$1} = $2;
-END { print map {sprintf "%20.20s | %16.16s | %s\n",@$_;} sort {$b->[1] cmp $a->[1]} @m }
-'
-#/var/spool/mail/$USER
-  #printf 'f *\nx\n' | mail |  perl -e '@_=<>; shift @_; print shift @_; print reverse @_'
-}
-
-nb_git_create() {
-# NB 19.02.15 root@pi:puppet# nb_git_create puppet/data
-# NB 19.02.15 Initialized empty Git repository in /home/git/puppet/data.git/
-# NB 19.02.15 Cloning into 'data'...
-# NB 19.02.15 warning: You appear to have cloned an empty repository.
-# NB 19.02.15 Got to directory: data
-# NB 19.02.15 Reinitialized existing Git repository in /etc/puppet/data/.git/
-# NB 19.02.15 [master (root-commit) 3ea2a65] Created by nb_git_create
-# NB 19.02.15  1 file changed, 7 insertions(+)
-# NB 19.02.15  create mode 100644 README.md
-# NB 19.02.15 Counting objects: 3, done.
-# NB 19.02.15 Compressing objects: 100% (2/2), done.
-# NB 19.02.15 Writing objects: 100% (3/3), 272 bytes, done.
-# NB 19.02.15 Total 3 (delta 0), reused 0 (delta 0)
-# NB 19.02.15 To git@git.nbdom.net:puppet/data.git
-# NB 19.02.15  * [new branch]      master -> master
-# NB 19.02.15 Branch master set up to track remote branch master from origin.
-# NB 19.02.15 fatal: remote origin already exists.
-# NB 19.02.15 Branch master set up to track remote branch master from origin.
-# NB 19.02.15 Everything up-to-date
-  declare name="${1%.git}"
-  declare dir=$(basename $name)
-  declare repo='git@git.nbdom.net'
-
-  #
-  # Check, create repo on server
-  #
-  [ -e "$dir" ] && echo ">$dir already exists!" 1>&2 && return 1
-
-  ssh git@git.nbdom.net "git init --bare ${name}.git" || return
-  git clone $repo:${name}.git || return
-
-  echo ">Got to directory: $dir"
-  cd $dir || return
-
-  #
-  # Create files
-  #
-  echo "$name
-=============
-
-## Synopsis
-
-DESCRIPTION
-" > README.md
-
-  #
-  # Update repo
-  #
-  git init
-  git add *
-  git commit -m "Created by $FUNCNAME"
-  git push --set-upstream origin master
-  git remote add origin $repo:${name}.git
-}
-
-nb_git_clone() {
-  git clone git@git.nbdom.net:${1%.git}.git
-}
-
-git-commit-push() {
-  git commit -m "$@" -a
-  git push #|| echo "Try: git push --set-upstream origin master"
-}
-
-git-commit-push-add() {
-  git add .
-  git-commit-push "$@"
-}
-
-puppet-upgrade-modules() {
-  local m
-  local pwd=$PWD
-  cd /etc/puppet/modules
-  for m in $(puppet module list | awk '/\(.*v/ {print $2}'); do
-    puppet module upgrade "$m"
-  done
-  cd $pwd
-}
-
-nb_rb() {
-  ruby -r/etc/puppet/modules/nb/lib/nb.rb -e "$@"
-}
-
-nb_hl() {
+hl() {
   cat | grep --color=auto -E "(^|($@))"
 }
 
-ls-tree() {
+ls_tree() {
   tree -tDphug
 }
 
-find-sort-mtime() {
+find_sort_mtime() {
   (
     if [ -n "$DARWIN" ]; then
       find $@ -type f -exec stat -f '%m'$'\t''%N' {} \;
@@ -270,102 +118,9 @@ find-sort-mtime() {
   ) | sort -k1 -n | cut -f 2 | head
 }
 
-nb_alert() {
-  local cmd=". $NB_ROOT/etc/profile"
-  local host=macbook.brighton.loc
-  case "$1" in
-    led)
-      host=pi.brighton.loc
-      cmd="$cmd && echo $FUNCNAME > /var/run/gpiod.sock"
-    ;;
-    say)
-      host=pi.brighton.loc
-      shift
-      cmd="$cmd && say <<< \"$@\""
-    ;;
-    beep)
-      host=pi.brighton.loc
-      cmd="$cmd && play 2>/dev/null -v 5 /home/pi/python_games/beep1.ogg"
-    ;;
-    -h|-help|--help)
-      echo "Usage: $FUNCNAME [led|say|beep|-h] OR TEXT"
-      return
-    ;;
-    *)
-      host=macbook.brighton.loc
-      shift
-      cmd="$cmd && mac-xmessage \"$FUNCNAME: $@\" 1>/dev/null"
-    ;;
-  esac
-  cmd="bash -c '$cmd'"
-
-  local ip=`dig +short $host`
-  [ -z "$ip" ] && echo "Can't resolve macbook.brighton.loc" && return 1
-
-  nb_ips | grep -qFm1 "$ip" || cmd="ssh -o BatchMode=yes $host -- $cmd"
-
-  #[ "$USER" != "nico" ] && cmd="su - nico -c '$cmd'"
-  [ "$USER" != "nico" ] && cmd="sudo -u nico -- $cmd"
-# NB 09.06.15   if [ "$USER" != "nico" ]; then
-# NB 09.06.15     cmd="sudo -u nico -- $cmd"
-# NB 09.06.15   else
-# NB 09.06.15     cmd="echo '$cmd'"
-# NB 09.06.15   fi
-  eval "$cmd"
-}
-
-nb_ips() {
-  ifconfig | perl -ne '/^\s*inet (?:addr:)?([\d\.]+)/ and $1 ne "127.0.0.1" and print "$1\n"'
-}
-
-nb_radio_play() {
-  local radios="\
-1 | FranceInter   | http://www.tv-radio.com/station/france_inter_mp3/france_inter_mp3-128k.m3u
-2 | Indie         | http://107.155.126.42:17160/listen.pls
-3 | FranceInfo    | http://players.creacast.com/creacast/france_info/playlist.m3u
-4 | FranceCulture | http://www.tv-radio.com/station/france_culture_mp3/france_culture_mp3-128k.m3u 
-
-Choose one > \
-"
-  if [ -z "$@" ]; then
-    read -p "$radios"
-  else
-    REPLY="$@"
-  fi
-
-  test -z "$REPLY" 2>/dev/null && return
-  awk -F '|' '$1 == '$REPLY' {print $3; exit}' <<< "$radios" | sed 's/^ //' | xargs mplayer 2>/dev/null
-}
-
-# NB 06.07.15 alias nb_img2jpg='convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85%'
-# NB 06.07.15 
-# NB 06.07.15 nb_img_compress() {
-# NB 06.07.15   local IFS=$'\n' i='' j=''
-# NB 06.07.15   for i in $@; do
-# NB 06.07.15     [ -e "$i" ] || continue
-# NB 06.07.15     j="${i%.*}.jpg"
-# NB 06.07.15     echo "$i -> $j"
-# NB 06.07.15     nb_img2jpg $i $j || continue
-# NB 06.07.15     [ "$i" != "$j" ] && rm "$i"
-# NB 06.07.15   done
-# NB 06.07.15 }
-# NB 06.07.15 
-# NB 06.07.15 nb_img_compress_gray() {
-# NB 06.07.15   # See: http://www.imagemagick.org/script/command-line-options.php#colorspace
-# NB 06.07.15   # See: convert -list colorspace
-# NB 06.07.15   local IFS=$'\n' i='' j=''
-# NB 06.07.15   for i in $@; do
-# NB 06.07.15     [ -e "$i" ] || continue
-# NB 06.07.15     j="${i%.*}.jpg"
-# NB 06.07.15     echo "$i -> $j"
-# NB 06.07.15     nb_img2jpg -colorspace Gray -normalize -level 10%,90% -sharpen 0x1 $i $j || continue
-# NB 06.07.15     [ "$i" != "$j" ] && rm "$i"
-# NB 06.07.15   done
-# NB 06.07.15 }
-
 replace_tag_content() {
-  declare tag="$1"; shift
-  declare content="$@"
+  declare tag; tag="$1"; shift
+  declare content; content="$@"
   perl -ne 'BEGIN {
 $tag = shift(@ARGV)." - replace_tag_content";
 $t1 = "# >>> $tag";
diff --git a/etc/profile.d/darwin.sh b/etc/profile.d/darwin.sh
new file mode 100644 (file)
index 0000000..82e379d
--- /dev/null
@@ -0,0 +1,18 @@
+[ -z "$DARWIN" ] && return 0
+
+md5sum() {
+  md5 $@ | sed "s/^MD5 (\(.*\)) = \(.*\)$/\2  \1/"
+}
+
+mac-xmessage() {
+  osascript -e "tell app \"System Events\" to display dialog \"$@\""
+}
+
+mac-config() {
+  echo "Finder path           : YES"
+  defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
+  echo "Finder quit           : YES"
+  defaults write com.apple.finder QuitMenuItem -bool YES
+  echo "Finder show all files : FALSE"
+  defaults write com.apple.finder AppleShowAllFiles FALSE
+}
diff --git a/etc/profile.d/git.sh b/etc/profile.d/git.sh
new file mode 100644 (file)
index 0000000..fd53699
--- /dev/null
@@ -0,0 +1,9 @@
+git_commit_push() {
+  git commit -m "$@" -a
+  git push #|| echo "Try: git push --set-upstream origin master"
+}
+
+git_commit_push_add() {
+  git add .
+  git-commit-push "$@"
+}
index 679a7f36f9f4edadfb4907dd9370993c20f54d96..efb10da165cd40131f66200d279f62f0285f441f 100644 (file)
@@ -1,3 +1,3 @@
-export PERL5LIB=`nb_env_add_path "$PERL5LIB" "$NB_ROOT/lib/perl"`
-export RUBYLIB=`nb_env_add_path "$RUBYLIB" "$NB_ROOT/lib/ruby|"`
-export PYTHONPATH=`nb_env_add_path "$PYTHONPATH" "$NB_ROOT/lib/python"`
+export PERL5LIB=`env_add_path "$PERL5LIB" "$NB_ROOT/lib/perl"`
+export RUBYLIB=`env_add_path "$RUBYLIB" "$NB_ROOT/lib/ruby|"`
+export PYTHONPATH=`env_add_path "$PYTHONPATH" "$NB_ROOT/lib/python"`
diff --git a/etc/profile.d/nb.sh b/etc/profile.d/nb.sh
new file mode 100644 (file)
index 0000000..095608f
--- /dev/null
@@ -0,0 +1,156 @@
+nb_mails() {
+  printf '| 1-$ cat\nx\n' | mail | perl -MDate::Manip -MEncode -ne '
+BEGIN { $SIG{__WARN__} = sub{ } }
+$. == 2 and print;
+/^From / .. /^$/ or next;
+chomp;
+if ($_ eq "") {
+  $h{From} =~ s/^.*?([^<\s]+@[^\s>]+).*?$/$1/;
+  $h{Date} = &UnixDate($h{Date},"%Y-%m-%d %H:%M");
+  $h{Subject} = decode("MIME-Header",$h{Subject});
+  push(@m,[
+    $h{From},
+    $h{Date},
+    $h{Subject},
+  ]);
+  %h = ();
+  next;
+}
+/^(Date|Subject|From): (.*)$/ and $h{$1} = $2;
+END { print map {sprintf "%20.20s | %16.16s | %s\n",@$_;} sort {$b->[1] cmp $a->[1]} @m }
+'
+#/var/spool/mail/$USER
+  #printf 'f *\nx\n' | mail |  perl -e '@_=<>; shift @_; print shift @_; print reverse @_'
+}
+
+nb_git_create() {
+# NB 19.02.15 root@pi:puppet# nb_git_create puppet/data
+# NB 19.02.15 Initialized empty Git repository in /home/git/puppet/data.git/
+# NB 19.02.15 Cloning into 'data'...
+# NB 19.02.15 warning: You appear to have cloned an empty repository.
+# NB 19.02.15 Got to directory: data
+# NB 19.02.15 Reinitialized existing Git repository in /etc/puppet/data/.git/
+# NB 19.02.15 [master (root-commit) 3ea2a65] Created by nb_git_create
+# NB 19.02.15  1 file changed, 7 insertions(+)
+# NB 19.02.15  create mode 100644 README.md
+# NB 19.02.15 Counting objects: 3, done.
+# NB 19.02.15 Compressing objects: 100% (2/2), done.
+# NB 19.02.15 Writing objects: 100% (3/3), 272 bytes, done.
+# NB 19.02.15 Total 3 (delta 0), reused 0 (delta 0)
+# NB 19.02.15 To git@git.nbdom.net:puppet/data.git
+# NB 19.02.15  * [new branch]      master -> master
+# NB 19.02.15 Branch master set up to track remote branch master from origin.
+# NB 19.02.15 fatal: remote origin already exists.
+# NB 19.02.15 Branch master set up to track remote branch master from origin.
+# NB 19.02.15 Everything up-to-date
+  declare name="${1%.git}"
+  declare dir=$(basename $name)
+  declare repo='git@git.nbdom.net'
+
+  #
+  # Check, create repo on server
+  #
+  [ -e "$dir" ] && echo ">$dir already exists!" 1>&2 && return 1
+
+  ssh git@git.nbdom.net "git init --bare ${name}.git" || return
+  git clone $repo:${name}.git || return
+
+  echo ">Got to directory: $dir"
+  cd $dir || return
+
+  #
+  # Create files
+  #
+  echo "$name
+=============
+
+## Synopsis
+
+DESCRIPTION
+" > README.md
+
+  #
+  # Update repo
+  #
+  git init
+  git add *
+  git commit -m "Created by $FUNCNAME"
+  git push --set-upstream origin master
+  git remote add origin $repo:${name}.git
+}
+
+nb_git_clone() {
+  git clone git@git.nbdom.net:${1%.git}.git
+}
+
+nb_rb() {
+  ruby -r/etc/puppet/modules/nb/lib/nb.rb -e "$@"
+}
+
+nb_alert() {
+  local cmd=". $NB_ROOT/etc/profile"
+  local host=macbook.brighton.loc
+  case "$1" in
+    led)
+      host=pi.brighton.loc
+      cmd="$cmd && echo $FUNCNAME > /var/run/gpiod.sock"
+    ;;
+    say)
+      host=pi.brighton.loc
+      shift
+      cmd="$cmd && say <<< \"$@\""
+    ;;
+    beep)
+      host=pi.brighton.loc
+      cmd="$cmd && play 2>/dev/null -v 5 /home/pi/python_games/beep1.ogg"
+    ;;
+    -h|-help|--help)
+      echo "Usage: $FUNCNAME [led|say|beep|-h] OR TEXT"
+      return
+    ;;
+    *)
+      host=macbook.brighton.loc
+      shift
+      cmd="$cmd && mac-xmessage \"$FUNCNAME: $@\" 1>/dev/null"
+    ;;
+  esac
+  cmd="bash -c '$cmd'"
+
+  local ip=`dig +short $host`
+  [ -z "$ip" ] && echo "Can't resolve macbook.brighton.loc" && return 1
+
+  nb_ips | grep -qxFm1 "$ip" || cmd="ssh -o BatchMode=yes $host -- $cmd"
+
+  #[ "$USER" != "nico" ] && cmd="su - nico -c '$cmd'"
+  [ "$USER" != "nico" ] && cmd="sudo -u nico -- $cmd"
+# NB 09.06.15   if [ "$USER" != "nico" ]; then
+# NB 09.06.15     cmd="sudo -u nico -- $cmd"
+# NB 09.06.15   else
+# NB 09.06.15     cmd="echo '$cmd'"
+# NB 09.06.15   fi
+  eval "$cmd"
+}
+
+nb_ips() {
+  ifconfig | perl -ne '/^\s*inet (?:addr:)?([\d\.]+)/ and $1 ne "127.0.0.1" and print "$1\n"'
+}
+
+nb_radio_play() {
+  local radios="\
+1 | FranceInter   | http://www.tv-radio.com/station/france_inter_mp3/france_inter_mp3-128k.m3u
+2 | Indie         | http://107.155.126.42:17160/listen.pls
+3 | FranceInfo    | http://players.creacast.com/creacast/france_info/playlist.m3u
+4 | FranceCulture | http://www.tv-radio.com/station/france_culture_mp3/france_culture_mp3-128k.m3u 
+
+Choose one > \
+"
+  if [ -z "$@" ]; then
+    read -p "$radios"
+  else
+    REPLY="$@"
+  fi
+
+  test -z "$REPLY" 2>/dev/null && return
+  awk -F '|' '$1 == '$REPLY' {print $3; exit}' <<< "$radios" | sed 's/^ //' | xargs mplayer 2>/dev/null
+}
+
diff --git a/etc/profile.d/puppet.sh b/etc/profile.d/puppet.sh
new file mode 100644 (file)
index 0000000..6b4fb5f
--- /dev/null
@@ -0,0 +1,19 @@
+puppet2yaml() {
+  perl -pe '
+s/^(.*)\{(.*?:)\s*/$1:\n  $2\n/;
+s/\s*=>\s*/: /;
+s/,\s*/\n/;
+s/\s*\}\s*//;
+' $@
+}
+
+puppet_upgrade_modules() {
+  local m
+  local pwd=$PWD
+  cd /etc/puppet/modules
+  for m in $(puppet module list | awk '/\(.*v/ {print $2}'); do
+    puppet module upgrade "$m"
+  done
+  cd $pwd
+}
+
index 9d461240b209b21d02b5e015a30af65d417e5e4f..937880ea4ba6eb3d95346f1bd935ed4dabd216cf 100644 (file)
@@ -3,6 +3,7 @@ use strict;
 
 use Encode qw(&encode &decode &encode_utf8 &decode_utf8 &from_to);
 use Carp;
+use POSIX;
 
 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION $VAR1);
 
@@ -273,18 +274,6 @@ sub sec2h {
 
        return sprintf("\%d day(s) %02d:%02d:%02d",$days,$hours,$minutes,$seconds);
 
-# NB 10.05.11  my $time = shift @_;
-# NB 10.05.11 
-# NB 10.05.11  my $d = int(($time / (60 * 60 * 60))+0.6);
-# NB 10.05.11 
-# NB 10.05.11  my $h = int($time / (60 * 60))-($d*24);
-# NB 10.05.11 
-# NB 10.05.11  my $m = int($time / 60) % 60;
-# NB 10.05.11 
-# NB 10.05.11  my $s = $time % 60;
-# NB 10.05.11 
-# NB 10.05.11  return sprintf("\%d day(s) %02d:%02d:%02d",$d,$h,$m,$s);
-
 }
 
 sub oct2h {
@@ -293,8 +282,8 @@ sub oct2h {
 
        if ($o >= 1099511627776) { return(sprintf('%.2fT',($o/1099511627776))); } # T
        elsif ($o >= 1073741824) { return(sprintf('%.2fG',($o/1073741824))); } # G
-       elsif ($o >= 1048576) { return(int($o/1048576)."M"); } # M
-       elsif ($o >= 1024) { return(int($o/1024)."K"); } # K
+       elsif ($o >= 1048576) { return(POSIX::ceil($o/1048576)."M"); } # M
+       elsif ($o >= 1024) { return(POSIX::ceil($o/1024)."K"); } # K
        else { return $o."bytes"; }
 
 }