Ontem antes de dormir estava baixando máquinas virtuais ubuntu e fedora pra ver o que eles mudaram nas suas versões mais recentes. Meu link doméstico não é gigantesco. Somente 1MB. Então tenho um down de 120 KB/s. O download completo dava uns 3,1 GB. Umas 5 horas de down. Comecei o download 0:30h. Eu às 2h da madruga tava ficando com sono. E o medo de dar alguma merda no download e eu não ter como reverter. era grande. Então, fiz um gerenciador de downloads simples e no meu caso eficiente.
Segue abaixo:
#!/bin/bash
<------------------------------------------------------------------------------------------------------------------->
# Verify Root id
sleep 2s
if [ "$(id -u)" != "0" ]; then
echo
clear && echo "You must execute this script as root user! " && exit
else
clear && echo "You are root. For that reason, I going to continue executing this one"
fi
# Environment Variables
rest=sleep 2s
clear && echo "Which is the file format?"
read EXTENSAO
$rest && clear
FILE=`ls | grep *.$EXTENSAO`
FILESIZE_parcial=`/usr/bin/du -m $FILE | /usr/bin/cut -f1`
PID_FIREFOX=`ps aux | grep firefox-bin | awk {'print $2'} | tail -n2 | head -n1`
#PIDOF_FIREFOX=`/bin/pidof firefox-bin`
<-------------------------------------------------------------------------------------------------------------------->
# Locate the file
echo "Where is the file?"
read directory
$rest && clear
# Verify size file
echo "What is size file that you are downloading?"
read FILESIZE_total
$rest && echo "Locating the file." && $rest
# Go to directory of file
cd $directory
# Comparison with if and case + Kill firefox process + Shutdown
if [ $FILESIZE_parcial != $FILESIZE_total ]; then
echo "The chosen file is being downloaded yet. So do not do anything"
else
sleep 2s && clear && echo "Download was finished successfull"
/bin/kill -9 $PID_FIREFOX
echo "Killing Firefox process." && sleep 2s && echo "Firefox process is dead" && clear && sleep 2s && echo "Would you like to turn off the machine now?"
read answer
case $answer in
Y|y) clear && echo "Turn off activated. If you do not want it, stop this script now. You have 20 seconds for do it." && sleep 20s && /sbin/shutdown -h +5
;;
*) sleep 2s && clear && echo "OK. If you do not want turn off the machine, fine. Thank you. See you later";;
esac
fi
Quem quiser pode baixar o script em arquivo no endereço: http://www.4shared.com/file/xUnaebMk/kill.html
Nenhum comentário:
Postar um comentário