Register
It is currently Wed Aug 20, 2014 6:23 pm

Kill md5sum inside parentheses


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Tue Feb 09, 2010 10:10 am   
User avatar

Joined: Sun Nov 01, 2009 8:59 am
Posts: 23
Location: Try to guess!
Hi, i've completed another version of my backup script, this time heavily relying on zenity to boost user friendliness.
There's only one thing i can't figure out. If the user clicks "Cancel" in the zenity dialog the dialog will close but the MD5 would still complete (and i don't want to wait for the error dialog to appear). I can't find a place to put "killall md5sum" so that it's executed immediately after clicking "Cancel".

Code:
while [ "$dirsum" != "$rightsum" ]; do
   (   
      echo $'\n'  #Needed by the progress dialog to start pulsating
      dirsum=`md5sum $pathh/$filename.7z`
      dirsum=${dirsum:0:32}
   )|
      zenity --progress --pulsate --title="MD5" --text="Checking MD5 checksum of copied file..." --auto-close      #KILL MD5SUM IF USER CANCELS!
      if [ "$?" != 0 ]
         then zenity --warning --title "CANCELED" --text "Aborted by user, FILES NOT DELETED."
         exit
      fi
      if [ "$dirsum" != "$rightsum" ]; then
         if zenity --question --title "WARNING" --text "WARNING: File corrupted during copy. Try again?"
         then $DoNothing  #fake var
         else zenity --error --title "ERROR" --text "Copied file still corrupted, check for
errors on the target file system."; exit
         fi
      fi
done


Top
 Profile  
 PostPosted: Fri Feb 19, 2010 10:54 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
Oh boy, this was actually a tricky one.

It seemed easiest to use the auto-kill option for zenity instead of auto-close. But, to allow for this, I used two scripts.
The first is the main controller script, foo.sh:
Code:
#!/bin/bash

./bar.sh
if [ "$?" != 0 ]; then
    zenity --warning --title "CANCELED" --text "Aborted by user, FILES NOT DELETED."
    exit
fi


The second actually does the work. Of course, it needs to be cleaned up, but you can probably take it from here. I just touched a file if the sums matched to avoid some of the complications of communicating with subshells, zenity, etc. This is bar.sh:
Code:
#!/bin/bash

path=/some/path
filename=cool_file.txt
dirsum=foobar
rightsum=41eb1e3a6420cec82a32c2ad2a8711e7
nothing=baz
matchfile=/home/thobbs/.matchfile

if [ -e "$matchfile" ]; then
    rm "$matchfile"
fi

while true; do
    (
       echo $'\n'
       dirsum=`md5sum $path/$filename`
       dirsum=${dirsum:0:32}
       if [ "$dirsum" == "$rightsum" ]; then
           touch "$matchfile"
       fi
    ) | zenity --progress --pulsate --title="MD5" --text="Checking MD5 checksum of copied file..." --auto-kill
   
    if [ ! -e "$matchfile" ]; then
        if zenity --question --title="WARNING" --text="WARNING: File corrupted during copy. Try again?"; then
            $nothing
        else
            exit 0
        fi
    else
        zenity --info --title="MD5" --text="Sums matched."
        rm "$matchfile"
        exit 0 # the sums matched
    fi
done


I hope that helps! It was an interesting problem.

- thobbs


Last edited by thobbs on Sun Feb 21, 2010 9:49 pm, edited 1 time in total.

Top
 Profile  
 PostPosted: Sat Feb 20, 2010 7:05 pm   
User avatar

Joined: Sun Nov 01, 2009 8:59 am
Posts: 23
Location: Try to guess!
JUST A QUICK POST:
In a different version of that script i've done this (this is just a quickie as i'm posting a new a new excitingly mindfucking thread!):

Code:
function doMD5
{
md5=`md5sum $someBigFile`
echo ${md5:0:32}  # Kind of returning
}

(
echo $'\n'
summ="$(doMD5)" &
)|
zenity --progress --pulsate --title="MD5" --text="Saving MD5 checksum..." --auto-close
if [ "$?" != 0 ]
   then   
      zenity --warning --title "CANCELED" --text "Aborted by user, FILES NOT DELETED."
      kill `pidof -s md5sum`
      kill $$                            # No time to tell if i need this too, i think i'll leave it where it is for now
fi


There are other issues i need to address now --->


Top
 Profile  
 PostPosted: Sat Feb 20, 2010 9:39 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
Sister thread here: http://bashscripts.org/forum/viewtopic.php?f=7&t=1001&sid=679115af6e8ed55692bb2c7de7a2bb13


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP