Admins eHow SysAdmin Tips & Tricks

March 13, 2010

Shell script to show network speed

Filed under: CentOS,Debian,DreamBox,General — Tags: , , , , , , , , , — admin @ 11:37 am

The following shell script shows current download and upload speeds for the network interface you choose.

Copy the shell script in a file named, i.e: net_speed.sh

Then after setting execution permissions:

chmod a+x net_speed.sh

You can run the shell script passing as the first argument the network interface you want to monitor:

./net_speed.sh eth0

You will get a line like that:
eth0 DOWN:15 KB/s UP:880 B/s

This script works parsing /proc/net/dev file and calculating the difference between current transmitted or received bytes and their values one second ago.

#!/bin/bash

# This shell script shows the network speed, both received and transmitted.

# Usage: net_speed.sh interface
#   e.g: net_speed.sh eth0


# Global variables
interface=$1
received_bytes=""
old_received_bytes=""
transmitted_bytes=""
old_transmitted_bytes=""


# This function parses /proc/net/dev file searching for a line containing $interface data.
# Within that line, the first and ninth numbers after ':' are respectively the received and transmited bytes.
get_bytes()
{
    line=$(cat /proc/net/dev | grep $interface | cut -d ':' -f 2 | awk '{print "received_bytes="$1, "transmitted_bytes="$9}')
    eval $line
}


# Function which calculates the speed using actual and old byte number.
# Speed is shown in KByte per second when greater or equal than 1 KByte per second.
# This function should be called each second.
get_velocity()
{
    value=$1    
    old_value=$2

    let vel=$value-$old_value
    let velKB=$vel/1024
    if [ $velKB != 0 ];
    then
 echo -n "$velKB KB/s";
    else
 echo -n "$vel B/s";
    fi
}

# Gets initial values.
get_bytes
old_received_bytes=$received_bytes
old_transmitted_bytes=$transmitted_bytes

# Shows a message and waits for one second.
echo "Starting...";
sleep 1;
echo "";


# Main loop. It will repeat forever.
while true; 
do

    # Get new transmitted and received byte number values.
    get_bytes

    # Calculates speeds.
    vel_recv=$(get_velocity $received_bytes $old_received_bytes)
    vel_trans=$(get_velocity $transmitted_bytes $old_transmitted_bytes)

    # Shows results in the console.
    echo -en "$interface DOWN:$vel_recv\tUP:$vel_trans\r"

    # Update old values to perform new calculations.
    old_received_bytes=$received_bytes
    old_transmitted_bytes=$transmitted_bytes

    # Waits one second.
    sleep 1;

done

Source : Linux Clues

June 2, 2009

Force Download on nginx

Filed under: Nginx — Tags: , , — admin @ 9:05 pm

if you want force download on nginx for all files except images use the following config :

server{
	listen 80;
	server_name test.localhost;
	location / {
		root /Users/vasil/test;
		if ($request_filename !~* ^.*?\.(jpg)|(png)|(gif)){
			add_header Content-Disposition: "$request_filename";
		}
	}
}

June 1, 2009

What affects the download speed of torrents ?

Filed under: General,Torrent — Tags: , , — admin @ 1:43 pm

Torrent is a P2P (Peer to Peer) network , means there is no central server to send data for clients , instead the clients connect to each other directly and communicate the data , in such network the speed depends on many factors despite the fact how much is your internet connection download speed.

1.Leechers/Seeders Ratio
if a torrent has many leechers (downloaders) but few seeders (uploaders) , then the speed of download would be low. I guess the reason is obvious 🙂

2.Network routes between peers
different geographic locations are connected to each other with different connection types , some with fiber optics , some with satellites , some with wireless networks and etc.
so it really matters where the seeders and leechers are located. someone in US may get 10x speed rather than someone in EU for a same torrent just because of network routes.

3.The softwares
The torrent softwares ( Torrent Clients ) have different performances , I would recommend uTorrent for best performance.

May 3, 2009

How to download files from FTP account easily Using FireFox + Flashgot + Flashget

Filed under: General — Tags: , , , , — admin @ 5:35 pm

ftp5

I have a Torrent Hosting service from a site named LeaseTorrent.com , I am almost 2 years with them and they are really good 🙂 anyway it is not a review for them but I want to teach you how to use combination of Firefox + Flashgot + Flashget to download your files easily from any FTP server.

You need these tools :

FlashGet version 1.73 , download here ( dont download newer versions , they are full of ads and crap )
Lates version of Firefox , download here
Latest version of Flashgot extension , download here

download these softwares and install them on your PC , remember flashgot is an addon for Firefox.

after installations , access your FTP account by this url in Firefox : ftp://username:password@yourftphost.com
you will see something like this :

ftp1

enter any folder which you want to download its files , and right click on page and choose Flashget All :

ftp2

uncheck the first two options and click on OK :

ftp3

on the next page specify where you want the files to be saved and click on OK.

ftp4

it’s done 🙂 all of your files will be added into flashgot queue and downloaded into the folder which you specified.

Powered by WordPress