Announcement

Collapse
No announcement yet.

dd show progressbar

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Firstly, a nitpick, "Enter root password" is wrong; on ubuntu derived distros there's no root password, to get sudo one enters your user's password.

    Originally posted by TheYikes View Post
    Code:
    echo "$password" | sudo -S ...
    That's not nice... the password will be visible in the process list, and I suspect that pass phrases will give trouble.

    A "nicer" approach is to put the kdialog command in a script on its own:
    Code:
    #!/bin/bash
    kdialog --password "whatever you like"
    Put that somewhere in your $PATH, say ~/bin/sudopass.sh, and make it executable with chmod +x. Then,
    Code:
    export SUDO_ASKPASS=~/bin/sudopass.sh
    sudo -A  dd ....
    If you don't want to have your own script, you can use /usr/bin/ssh-askpass, but that doesn't let you control the prompt, and gives a warning.
    Regards, John Little

    Comment


      #17
      Originally posted by jlittle View Post
      To use that with dd, you'd have to capture its progress output, parse it, and generate the dbus messages. You'd also want to check that the message succeeded, in case the dialog was cancelled or closed.
      Part of me said "Challenge!". At first I resisted, but then I accepted.

      It was tricky because the output of dd has to be piped through something to turn CR (\r, ^M) to new lines, and the output of that was buffered, so it all came out at the end, defeating the purpose, and kdialog exits immediately if cancel is clicked.
      (It works with Gnu awk, it doesn't work with mawk, I don't know why; if your awk is not gawk, you might need to install it.)
      Code:
      #!/bin/bash
      
      n=2000
      sz=$((1024 * n))
      bytes=$((1024 * sz))
      echo $bytes bytes
      dbusref=$(kdialog --progressbar "running" $bytes)
      
      # an example, longish running dd, that does nothing
      dd if=/dev/urandom count=$sz bs=1K of=/dev/null status=progress oflag=sync |&
          stdbuf -oL awk -v RS=$'\r' '/^[0-9]+ bytes/ {print $1}' |
          while read number;do
              echo "<$number>"
              if ! qdbus $dbusref value $number 2> /dev/null; then
                  echo interrupted
                  break
              fi
          done
      
      ( if ! qdbus $dbusref value $bytes ; then
          exit
        fi
        qdbus $dbusref setLabelText complete
        sleep 2
        qdbus $dbusref close
      ) 2> /dev/null
      The stdbuf -oL just makes the awk output line buffered; it's supposed to be anyway, but isn't.
      If cancel is pressed, setting the value fails, the script exits the loop, and the pipes get closed, stopping dd.
      Regards, John Little

      Comment


        #18
        Hello again Jittle. Ok i have to say that's a hefty piece of script for a newbie but believe it or not it actually makes sense to me. I'm on the road at the moment but I'll definitely have a look at it when i get get home. Sad as this is to say it'll be the highlight of my day!! but i really get a kick out of scripting.

        Comment


          #19
          I did it for fun, don't feel obliged to pay it any attention. IMO a non-GUI utility is better with a non-GUI progress bar.
          i really get a kick out of scripting.
          I do too. I think knowing about the dbus, and qdbus or qdbusviewer, are useful things in the scripting toolbox these days.
          Regards, John Little

          Comment

          Working...
          X