Advertisement
AIDEMOIRE

ddv

Sep 3rd, 2013
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.24 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # ddv - `dd' with periodic status check
  4. #
  5. # ver 1.00 (09/01/2013) : Initial Release
  6.  
  7. # Copyright (c) 2013, Tomoaki Shimoyama
  8. # All rights reserved.
  9. #
  10. # [The BSD 2-Clause License]
  11. # Redistribution and use in source and binary forms, with or without
  12. # modification, are permitted provided that the following conditions are
  13. # met:
  14. #
  15. #  * Redistributions of source code must retain the above copyright notice,
  16. #    this list of conditions and the following disclaimer.
  17. #
  18. #  * Redistributions in binary form must reproduce the above copyright notice,
  19. #    this list of conditions and the following disclaimer in the
  20. #    documentation and/or other materials provided with the distribution.
  21. #
  22. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23. # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  24. # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  25. # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33.  
  34. DEFAULT_INTERVAL=180
  35.  
  36. if [ -z "$DDV" ] ; then
  37.     INTERVAL=$DEFAULT_INTERVAL
  38. else
  39.     INTERVAL=$( expr $( expr $DDV + 0 2> /dev/null ) + 0 )
  40.     if [ $INTERVAL -le 0 ] ; then INTERVAL=$DEFAULT_INTERVAL ; fi
  41. fi
  42.  
  43. sendsig() {
  44.     DD_PID=
  45.     CONTINUE=true
  46.     while [ $CONTINUE = true ] ; do
  47.         sleep $INTERVAL
  48.         if [ -z "$DD_PID" ] ; then
  49.             DD_PID=$( ps al \
  50.                 | grep -w dd \
  51.                 | grep -v grep \
  52.                 | grep -w $1 \
  53.                 | sed -e "s/  */ /g" \
  54.                 | cut -d " " -f 3 \
  55.                 )
  56.         fi
  57.         if [ ! -z "$DD_PID" ] ; then
  58.             kill -USR1 $DD_PID > /dev/null 2>&1
  59.             if [ $? -eq 0 ] ; then
  60.                 echo ; date
  61.             else
  62.                 DD_PID=
  63.                 CONTINUE=false
  64.             fi
  65.         else
  66.             CONTINUE=false
  67.         fi
  68.     done
  69. }
  70.  
  71. sendsig $$ &
  72. SENDSIG_PID=$!
  73.  
  74. fin() {
  75.     kill $SENDSIG_PID
  76. }
  77. trap fin EXIT
  78.  
  79. dd $@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement