9 de dezembro de 2010

Novo Gerenciador de Download

Comprei um livro especializado em Shell script e estou aderindo a novas políticas. Meu último script foi um gerenciador de downloads. Depois que comecei a estudar pelo livro, verifiquei  que meu último script era falho. Nem sempre funcionava como deveria. Então o refiz. Não mudou... muita coisa. Mas, algumas coisas mudaram.




#!/bin/bash
#<-------------------------------------------------------------------------------------------------------------->
# Verify Root id
clear
if [ "$(id -u)" != "0" ]; then
        echo "You must execute this script as root user! " && exit
fi

# Environment Variables
        echo "Tell me the path file? Ex: /root/firefox.tar.bz2"
        read FILE
        FILESIZE_partial=$(/usr/bin/du -h $FILE | /usr/bin/cut -f1)
        PID_FIREFOX=$(/bin/pidof firefox-bin)
        clear


#<------------------------------------------------------------------------------------------------------------->
# Verify size file
echo "What is size file that you are downloading? Ex: 161.7M"
read FILESIZE_total
clear

# Comparison with if and case + Kill firefox process + Shutdown
if [ "$FILESIZE_partial" != "$FILESIZE_total" ]; then
        echo "The chosen file is being downloaded yet. So do not do anything."
else
        echo "Download was finished successfull. Wait, I going to kill the firefox..."
        sleep 2s
        kill -9 $PID_FIREFOX
        clear
        echo "Would you like turn off your machine? (Y/N)"
                read turnoff
                case $turnoff in
                        Y|y) /sbin/shutdown -h now;;
                        *)   echo "OK." && exit;;
                esac

fi



Bom, é isso pessoal! Qualquer dúvida... só gritar... lssabino@hotmail.com



OBS: Irei tirar umas "férias". Por isso, não irei escreverei aos meus leitores por uns 40 dias. Só volto a escrever lá pro final de janeiro. Obrigado pessoal! FUI!

Nenhum comentário: