Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Friday, October 20, 2017

Bandwidth Stabilizer Script for Mikrotik Router

Bandwidth Stabilizer Script for Mikrotik Router


Bandwidth Stabilizer Script for Mikrotik Router

Internet connection by the Internet service provider (ISP) which has many clients that tends to increase with time goes. The problem comes when the increased number of clients that they have not comparable with the services that they purchased from the first party. From the client side like me can not do anything with ISP services are diminishing because of the large number of their clients. Of course ISP will dodge with a lot of reasons if called has provides with bad services. On this situation it is hard to say which one the best ISP that can provide a good services.

Internet connection that slower than standard bandwidth speed of which we should get caused a lot of possibilities. Such as the quality of the wireless equipment used, technical installation of the wireless network, interference frequencies are used, overload client that the ISP have, and etc. So I dont say that this script will be able to overcome the slow internet connection absolutely. This script just only help to stabilize the connection upon congested traffic, the rest just the ISP that knowing.

Congested Traffic to be one of the causes of ping enlarge that make connection to be slow. We will harness the ability of Mikrotik in conditioning ping and finding a bus way during congested traffic so that the connection does not hang on. But the most common problem was caused by technical problem associated with the ISP related to the number of clients that they have.

OK we get started immediately for Bandwidth Stabilizer Script On Mikrotik Winbox by making mangle rule on the firewall and queue tree

1. Login to the Winbox with account that you have. Then click the New Terminal menu and enter the following script at the cursor terminal window. As shown like the picture below
/ip firewall mangle add chain=prerouting protocol=icmp action=mark-connection new-connection-mark=ICMP_CONNECTION passthrough=yes comment="ICMP_CONNECTION" disabled=no
Still in the terminal window, enter the second mangle firewall script below. Right-click at the cursor and paste therein. As shown like the picture below.
/ip firewall mangle add chain=prerouting protocol=icmp connection-mark=ICMP_CONNECTION action=mark-packet new-packet-mark=ICMP_PACKET passthrough=no comment="ICMP_PACKET" disabled=no


Then you can see the result on the firewall window at mangle tab. The both script that we enter to the terminal window above will create a rule on the firewall mangle on the Mikrotik. As shown like the picture below.


2. The Next we are going to create a queue tree rule. Click on the New terminal again and enter the following script by right click at the cursor on the terminal window and paste therein, as shown like the picture below.
/queue tree add name="==PING_CONDITION==" parent=global-total packet-mark=ICMP_PACKET limit-at=0 queue=default priority=1 max-limit=0 burst-limit=0 burst-threshold=0 burst-time=0s


At last we going to see the third script that we have inserted by click on queues>Queue Tree. It will look like at the right picture above. From my experience these script just only to stabilize the connection to avoid hang on when browsing during congested traffic usually at the daytime. If you are curious you can try this! Good Luck!

Available link for download

Read more »

Monday, September 11, 2017

Bash Script to check after every one minute whether a user has logged in or not

Bash Script to check after every one minute whether a user has logged in or not



#!/bin/bash
# isuserloggedin.sh
# Usage: isuserloggedin.sh username
# Shell script which checks after every one minute whether a user has logged in
# or not
# You can also run script in background using & then foreground it to view result

if [ $# -ne 1 ]
then
echo "You supplied wrong arguments"
echo "usage : `basename $0` username"
exit 1
fi

isuserexist()
{
grep -w "$1" /etc/passwd > /dev/null

if [ $? -eq 1 ]
then
echo "$1 is not a valid user"
exit 1
fi
}

isuserexist $1
time=0
while true
do
# you can replace following two statements with
# if `who|grep $1 > /dev/null`
who|grep $1 > /dev/null
if [ $? -eq 0 ]
then
echo "User $1 is logged in "
if [ $time -gt 60 ]
then
hours=$((time/60))
minutes=$((time%60))
echo "He is logged in $hours hour(s) $minutes minute(s) late"
else
echo "He is logged in $time minute(s) late"
fi
exit 0

else
let time++

# You can use following formats also
# time=`expr $time + 1 `
# time=$((time+1))

sleep 60
fi
done

Output:
[root@localhost shell]# sh isuserloggedin.sh
you have suplied wrong arguments
usage : isuserloggedin.sh username
[root@localhost shell]# sh isuserloggedin.sh root
User root is logged in
He is logged in 0 minute(s) late
[root@localhost shell]# sh isuserloggedin.sh roott
roott is not a valid user
Run script in background
[root@localhost shell]# sh isuserloggedin.sh venu &
[1] 15917
[root@localhost shell]# User venu is logged in
He is logged in 3 minute(s) late

[1]+ Done sh isuserloggedin.sh venu
Run script in background then foreground it
[root@localhost shell]# sh isuserloggedin.sh venu &
[1] 16223
[root@localhost shell]# fg
sh isuserloggedin.sh venu
User venu is logged in
He is logged in 1 minute(s) late
[root@localhost shell]#

Available link for download

Read more »

Monday, July 24, 2017

Bash Script to Check whether a user has an account in your system

Bash Script to Check whether a user has an account in your system


#!/bin/bash
# validuser.sh
# Usage: validuser.sh username
# Script to check whether suplied user has an account in your system

if [ $# -ne 1 ]
then
echo "You supplied wrong arguments"
echo "Usage : `basename $0` user_name"
exit 1
fi

#grep -w "$1" /etc/passwd > /dev/null
grep -w "^$1" /etc/passwd > /dev/null
if [ $? -eq 1 ]
then
echo "$1 is not a valid user"
else
echo "$1 is a valid user"
fi

# Using greps -q option you can simplify and faster your script
# if `grep -qw "^$1" /etc/passwd`
# greps -q option prints nothing just returns exit status 0 or 1

Out Put:
[root@localhost shell]# sh validuser.sh
You supplied wrong arguments
usage : validuser.sh user_name
[root@localhost shell]# sh validuser.sh venu
venu is a valid user
[root@localhost shell]# sh validuser.sh venuk
venuk is not a valid user
[root@localhost shell]# sh validuser.sh root
root is a valid user
[root@localhost shell]# sh validuser.sh roott
roott is not a valid user
[root@localhost shell]#

Available link for download

Read more »