Advertisement
Guest User

Tux Files - Script para bajar archivos (con Zenity y wget)

a guest
Dec 16th, 2010
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.20 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. DOWNLOAD() {
  4.  
  5. rand="$RANDOM `date`"
  6. pipe="/tmp/pipe.`echo '$rand' | md5sum | tr -d ' -'`"
  7. mkfifo $pipe
  8. wget -c $1 2>&1 | while read data;do
  9. if [ "`echo $data | grep '^Length:'`" ]; then
  10. total_size=`echo $data | grep "^Length:" | sed 's/.*\((.*)\).*/\1/' | tr -d '()'`
  11. fi
  12. if [ "`echo $data | grep '[0-9]*%' `" ];then
  13. percent=`echo $data | grep -o "[0-9]*%" | tr -d '%'`
  14. current=`echo $data | grep "[0-9]*%" | sed 's/\([0-9BKMG.]\+\).*/\1/' `
  15. speed=`echo $data | grep "[0-9]*%" | sed 's/.*\(% [0-9BKMG.]\+\).*/\1/' | tr -d ' %'`
  16. remain=`echo $data | grep -o "[0-9A-Za-z]*$" `
  17. echo $percent
  18. echo "#Downloading $1\n$current of $total_size ($percent%)\nSpeed : $speed/Sec\nEstimated time : $remain"
  19. fi
  20. done > $pipe &
  21.  
  22. wget_info=`ps ax |grep "wget.*$1" |awk '{print $1"|"$2}'`
  23. wget_pid=`echo $wget_info|cut -d'|' -f1 `
  24.  
  25. zenity --progress --auto-close --text="Connecting to $1\n\n\n" --width="350" --title="Downloading"< $pipe
  26. if [ "`ps -A |grep "$wget_pid"`" ];then
  27. kill $wget_pid
  28. fi
  29. rm -f $pipe
  30. }
  31.  
  32. if [ $1 ];then
  33. DOWNLOAD "$1"
  34. else
  35. dllink=$(zenity --entry --text "Your download link :" --width="350" --entry-text "" --title="Download url")
  36. if [ $dllink ];then
  37. DOWNLOAD "$dllink"
  38. fi
  39. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement