Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../opt/sharedra.../extras
File: bwshapectl.sh
#!/bin/bash
[0] Fix | Delete
[1] Fix | Delete
DEVICE="eth0"
[2] Fix | Delete
[3] Fix | Delete
if [ ! -z $2 ]; then
[4] Fix | Delete
DEVICE="$2"
[5] Fix | Delete
fi
[6] Fix | Delete
[7] Fix | Delete
if [ "$1" == "--disable" ]; then
[8] Fix | Delete
tc qdisc delete dev $DEVICE root || echo "Unable to remove rules, did you specify the right device? Or were rules already removed?"
[9] Fix | Delete
logger IMHADMIN "Disabled bandwidtch shaping on $DEVICE"
[10] Fix | Delete
exit;
[11] Fix | Delete
fi
[12] Fix | Delete
[13] Fix | Delete
[14] Fix | Delete
if [ "$1" == "--enable" ]; then
[15] Fix | Delete
[16] Fix | Delete
########################################Begin Shaping Code
[17] Fix | Delete
#Delete any qdiscs in place (reverts to standard pfifo)
[18] Fix | Delete
# tc qdisc delete dev $DEVICE root
[19] Fix | Delete
[20] Fix | Delete
#Set Device and default 'marking' (language not correct)
[21] Fix | Delete
tc qdisc add dev $DEVICE root handle 1: htb default 90 || echo "Unable to use tc to do bandwidth shaping - did you specify the wrong device? Is it already enabled?"
[22] Fix | Delete
[23] Fix | Delete
#Set 'Base' limits that will apply to all derivative clases
[24] Fix | Delete
tc class add dev $DEVICE parent 1: classid 1: htb rate 90mbit ceil 100mbit || echo "Unable to use tc to do bandwidth shaping - did you specify the wrong device? Is it already enabled?"
[25] Fix | Delete
[26] Fix | Delete
#Set limits for default ":90"
[27] Fix | Delete
tc class add dev $DEVICE parent 1:1 classid 1:90 htb rate 85mbit ceil 88mbit || echo "Unable to use tc to do bandwidth shaping - did you specify the wrong device? Is is already enabled?"
[28] Fix | Delete
[29] Fix | Delete
logger IMHADMIN "Enabled 100mbit bandwidtch shaping on $DEVICE"
[30] Fix | Delete
exit
[31] Fix | Delete
fi
[32] Fix | Delete
[33] Fix | Delete
[34] Fix | Delete
if [ "$1" == "--show" ]; then
[35] Fix | Delete
#show all rules
[36] Fix | Delete
tc -s -d qdisc show dev $DEVICE;tc -s -d class show dev $DEVICE;tc -s -d filter show dev $DEVICE || echo "Couldn't list bandwish shaping properties - You used $DEVICE, is that right?"
[37] Fix | Delete
exit;
[38] Fix | Delete
fi
[39] Fix | Delete
[40] Fix | Delete
if [ "$1" == "--status" ]; then
[41] Fix | Delete
tc -s -d qdisc show dev $DEVICE | grep pfifo 1>/dev/null 2>/dev/null
[42] Fix | Delete
if [ "$?" -eq 0 ]; then
[43] Fix | Delete
echo "Bandwidth shaping NOT enabled on $DEVICE";
[44] Fix | Delete
exit 0;
[45] Fix | Delete
elif [ "$?" -eq 1 ]; then
[46] Fix | Delete
echo "Bandwidth shaping enabled on $DEVICE"
[47] Fix | Delete
exit 1;
[48] Fix | Delete
else
[49] Fix | Delete
echo "You shouldn't see this."
[50] Fix | Delete
exit;
[51] Fix | Delete
fi
[52] Fix | Delete
fi
[53] Fix | Delete
[54] Fix | Delete
echo "This script enables/disabled traffic shaping
[55] Fix | Delete
Usage:
[56] Fix | Delete
$0 --enable - Enables bandwidth shaping on eth0
[57] Fix | Delete
$0 --disable - Disables bandwidth shaping on eth0
[58] Fix | Delete
$0 --status - Returns 1 if no shaping is enabled, 0 if enabled. (this
[59] Fix | Delete
is primarily for shell scripting/a nagios check if we need it)
[60] Fix | Delete
$0 --show - Displays the bandwidth shaping properties.
[61] Fix | Delete
If no shaping is in place a default setup will have default qdisc
[62] Fix | Delete
of pfifo and will will look similar to the following:
[63] Fix | Delete
qdisc pfifo_fast 0: bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
[64] Fix | Delete
Sent 383480 bytes 3266 pkt (dropped 0, overlimits 0 requeues 0)
[65] Fix | Delete
rate 0bit 0pps backlog 0b 0p requeues 0
[66] Fix | Delete
[67] Fix | Delete
If bandwidth shaping is enabled, it will have the htb qdisk in place:
[68] Fix | Delete
qdisc htb 1: r2q 10 default 90 direct_packets_stat 0 ver 3.17
[69] Fix | Delete
Sent 6022 bytes 67 pkt (dropped 0, overlimits 0 requeues 0)
[70] Fix | Delete
rate 0bit 0pps backlog 0b 0p requeues 0
[71] Fix | Delete
class htb 1: root prio 0 quantum 200000 rate 90000Kbit ceil 100000Kbit
[72] Fix | Delete
burst 12847b/8 mpu 0b overhead 0b cburst 14100b/8 mpu 0b overhead 0b level 0
[73] Fix | Delete
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
[74] Fix | Delete
rate 0bit 0pps backlog 0b 0p requeues 0
[75] Fix | Delete
lended: 0 borrowed: 0 giants: 0
[76] Fix | Delete
tokens: 1142 ctokens: 1128
[77] Fix | Delete
[78] Fix | Delete
class htb 1:90 root prio 0 quantum 200000 rate 85000Kbit ceil 88000Kbit
[79] Fix | Delete
burst 12218b/8 mpu 0b overhead 0b cburst 12595b/8 mpu 0b overhead 0b level 0
[80] Fix | Delete
Sent 6410 bytes 69 pkt (dropped 0, overlimits 0 requeues 0)
[81] Fix | Delete
rate 0bit 0pps backlog 0b 0p requeues 0
[82] Fix | Delete
lended: 69 borrowed: 0 giants: 0
[83] Fix | Delete
tokens: 1131 ctokens: 1127
[84] Fix | Delete
[85] Fix | Delete
If you need to specify an alternate device (a few servers do not have their primary adapter as eth0),
[86] Fix | Delete
you can do the following:
[87] Fix | Delete
$0 --enable eth1
[88] Fix | Delete
$0 --disable eth1
[89] Fix | Delete
"
[90] Fix | Delete
[91] Fix | Delete
exit
[92] Fix | Delete
[93] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function