#!/bin/bash # alfplayer # 2014-06-12 # # Test Parabola HTTP(S) and rsync mirror speeds. mail_to="your@mail.com" script_filename="$(basename "$0")" log_dir="$HOME/log/${script_filename}" if [[ ! -d ${log_dir} ]] ; then mkdir "${log_dir}" fi if [[ ! -w ${log_dir} ]] ; then echo -e "Can't write to log file directory: \"${log_dir}\". Nothing done." exit 1 fi echo "=> ${script_filename} started. Start time: $(date -u --rfc-3339=seconds)" >> "${log_dir}/${script_filename}" # Locking and send email on exit exit_trap() { if [[ ${mail_to} ]] ; then echo "=> Sending output to ${mail_to}" mail -s "[$(hostname)] ${script_filename}" "${mail_to}" < <(tail -n 1 /var/log/"${script_filename}"/*) rm -rf "$lockdir" fi } lockdir="/tmp/${script_filename}.lock" if mkdir "$lockdir" ; then # Remove lockdir when the script finishes, or when it receives a signal trap exit_trap 0 # remove directory when script finishes # Optionally create temporary files in this directory, because # they will be removed automatically: tmpfile="$lockdir/filelist" else echo >&2 "cannot acquire lock, giving up on $lockdir" exit 0 fi test() { echo -n "$(date -u --rfc-3339=seconds) " >> "${log_dir}/$repo" filename="$(wget --no-check-certificate -q ${url}/community/os/x86_64/community.db -O - | tar xzO | grep '^vtk-.*pkg.tar.*$')" wget --no-check-certificate -O /dev/null ${url}/community/os/x86_64/"${filename}" 2>&1 | sed -n -e 's|^.*(\([0-9.]\+ [KM]B/s\)).*$|\1|p' >> "${log_dir}/$repo" } # parabolagnulinux.mirrors.linux.ro repo=parabolagnulinux.mirrors.linux.ro url='http://parabolagnulinux.mirrors.linux.ro' test # repo.parabola.nu repo=repo.parabola.nu url='http://repo.parabola.nu' test # alfplayer.com repo=alfplayer.com url='http://alfplayer.com/parabola' test # snapshots.alfplayer.com repo=snapshots.alfplayer.com url='http://snapshots.alfplayer.com/parabola' test # yandex.ru repo=yandex url='http://mirror.yandex.ru/mirrors/parabola' test # https://parabola.goodgnus.com.ar/ repo=goodgnus url='https://parabola.goodgnus.com.ar' test # b.mirrors.fryxell.info # !! HTTP instead of HTTPS as listed in the file "mirrorlist" repo=b.mirrors.fryxell.info #url='https://parabola.fryxell.info' url='http://b.mirrors.fryxell.info/parabolagnulinux' test # custom file #repo="" #url="" #echo -n "$(date -u --rfc-3339=seconds) " >> "${log_dir}/$repo" #wget --no-check-certificate -O /dev/null "$url" 2>&1 | sed -n -e 's|^.*(\([0-9.]\+ [KM]B/s\)).*$|\1|p' >> "${log_dir}/$repo" echo "Rsync test" echo "Using amsn package (around 11 MB)" test_rsync() { echo -n "$(date -u --rfc-3339=seconds) " >> "${log_dir}/$repo" rm -f /tmp/"${script_filename}"-test.db rsync -L --no-motd ${SERVER}/community/os/x86_64/community.db /tmp/"${script_filename}"-test.db filename="$(tar xzOf /tmp/${script_filename}-test.db | grep '^amsn-.*pkg.tar.*$')" rsync -Lv --no-motd ${SERVER}/community/os/x86_64/"${filename}" /tmp/"${script_filename}"-testfile | \ grep -o '[0-9,.]* bytes/sec' >> "${log_dir}/$repo" rm -f /tmp/"${script_filename}"-testfile } repo=rsync_alfplayer.com SERVER="rsync://alfplayer.com:873/repos/parabola" test_rsync repo=rsync_snapshots_alfplayer SERVER="rsync://snapshots.alfplayer.com/repos/parabola" test_rsync repo=rsync_parabolagnulinux.mirrors.linux.ro SERVER="rsync://parabolagnulinux.mirrors.linux.ro/parabolagnulinux" test_rsync repo=rsync_repo.parabola.nu SERVER="rsync://repo.parabola.nu:875/repos" test_rsync repo=rsync_yandex SERVER="rsync://mirror.yandex.ru/mirrors/parabola" test_rsync repo=rsync_archlinux_unicamp SERVER="rsync://rsync.las.ic.unicamp.br/pub/archlinux" test_rsync echo "=> ${script_filename} finished successfully. Finish time: $(date -u --rfc-3339=seconds)" >> "${log_dir}/${script_filename}"