Monday, March 18, 2019

how to reload all kernel parameters in linux ?

You need to use the sysctl command which is used to modify kernel parameters at run time.
The parameters available are those listed under /proc/sys/.
Procfs is required for sysctl support in Linux. You can use sysctl command to both read and write sysctl variables.

Display Linux kernel parameters

Display all sysctl variables

The syntax is:
# sysctl variable
# sysctl -a
# sysctl -a | more

Sample output

vm.swappiness = 60
vm.user_reserve_kbytes = 131072
vm.vfs_cache_pressure = 100

To see value for kernel variable called kernel.hostname, enter:
# sysctl -n kernel.hostname

How do I set new values?

There are three methods to set new values for given kernel parameters as follows:

Method # 1: Setting value via procfs

You can use standard echo command to write data to variables (this temporary change):
# echo "value" > /proc/sys/location/variable
Echo “1” > /proc/sys/net/ipv4/conf/all/rp_filter

Method # 2: Temporary on the command line

Use sysctl command with -w option when you want to change a sysctl setting:
sysctl -w variable=value

To enable packet forwarding for IPv4, enter:
# sysctl -w net.ipv4.ip_forward=1


Method # 3: Configuration file /etc/sysctl.conf

This is recommended way. First open /etc/sysctl.conf file, enter:
# vi /etc/sysctl.conf

Now add value:
variable = value

example :

net.ipv4.ip_forward=1


Close and save the changes. Type the following command to load sysctl settings from the file /etc/sysctl.conf file:
# sysctl -p

OR
# sysctl -p /etc/sysctl.conf

The last method will load settings permanently at boot time from /etc/sysctl.conf file. Read man page of sysctl for information:
$ man sysctl


Reload settings from all system configuration files

Type the following command to reload settings from config files without rebooting the box:
# sysctl --system

For older versions (that is, if --system does not work):

# Load settings from /etc/sysctl.conf
sysctl -p

The settings are read from all of the following system configuration files:

/run/sysctl.d/*.conf
/etc/sysctl.d/*.conf
/usr/local/lib/sysctl.d/*.conf
/usr/lib/sysctl.d/*.conf
/lib/sysctl.d/*.conf
/etc/sysctl.conf


# Load settings from the specified file
sysctl -p /etc/sysctl.d/<whatever>.conf

example:

sysctl -p /etc/sysct.d/10-magic-sysrq.conf


Thursday, March 7, 2019

how to get symbolic link file size in linux ?

The name of the symbolic link remains fixed, but the file it is linked to is constantly changed by another application . The Motion application ensures that the symbolic link points to the correct file.

symbolic links: Refer to a symbolic path indicating the abstract location of another file

Using stat command will get  symbolic file size.


stat - display file or file system status


Syntax :

stat -Lc %s  < symbolic>

Where

-L, --dereference
                             follow links
-c  --format=FORMAT
                              use the specified FORMAT instead of the default; output a newline after            each use of FORMAT

%s     total size, in bytes


Example:  
                ls -lrt script*

 -rw-rw-r-- 1 ram ram 29366 Mar  6 01:37 script.txt
lrwxrwxrwx 1 ram ram    10 Mar 7 14:34 script -> script.txt


stat -Lc %s script
29366

Example2: using du command

du -b $(readlink -f script)

29366 /home/ram/script.txt

Monday, March 4, 2019

how to add or delete routes in linux ?


There are two commands which are useful either to add or delete route, those are  route and ip.
We will see how to change route using command route.

Understanding of routing

On Linux and UNIX systems, information on how packets are to be forwarded is stored in a kernel structure called a routing table. You need to manipulate this table when configuring your computer to talk to other computers across a network. The routing table can be used for both static and dynamic routing. Dynamic routing consists of the kernel making decisions as to which route, out of multiple present routes, a packet should take. Since dedicated routers and ISPs generally deal more with dynamic routing.



NAME
      route - show / manipulate the IP routing table

SYNOPSIS

      route [-CFvnee]

      route [-v] [-A family] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss M]
[window W] [irtt I] [reject] [mod] [dyn] [reinstate] [[dev] If]

      route [-v] [-A family] del [-net|-host] target [gw Gw] [netmask Nm] [metric N] [[dev] If]

      route [-V] [--version] [-h] [--help]




Adding route


sudo route add -net 192.168.3.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

sudo route add -net 192.168.3.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

View route

We can use

route -n
Or
sudo ip route show
Or
netstat -rn

Deleting route



sudo route del -net 192.168.3.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

sudo route del -net 192.168.3.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

A quick way to add default route



route add default gw 192.168.1.1

A  quick way to delete default route


route del default gw 192.168.1.1



Sunday, January 20, 2019

How to Check MySQL Database & Tables Size on linux ?

MySQL is a Relational Database Management System, widely used as a database system for Linux systems. This article will help you to calculate the size of tables and database in MySQL or MariaDB servers though SQL queries. MySQL stored all the information related to tables in a database in the information_schema database. We will use the information_schema table to find tables and databases size.


How to find each data base size ?


Check ALL Databases Size in MySQL



Using mysql query


SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM
information_schema.TABLES GROUP BY table_schema;


Sample output:


mysql> SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM
information_schema.TABLES GROUP BY table_schema
   -> ;
+--------------------+------------+
| Database           | Size (MB) |
+--------------------+------------+
| information_schema | 0.00878906 |
| mylabdb            | 0.00111008 |
| mysql              | 0.68704987 |
| performance_schema | 0.00000000 |
+--------------------+------------+



mysql> SELECT
   ->   table_schema 'Database Name',
   ->   SUM(data_length + index_length) 'Size in Bytes',
   ->   ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) 'Size in MiB'
   -> FROM information_schema.tables
   -> GROUP BY table_schema;





Check Single Table Size in MySQL Database


To find out the size of a single MySQL database called mylabdb (which displays the size of all tables in it) use the
following mysql query.


mysql> SELECT table_name AS "Table Name",ROUND(((data_length + index_length) / 1024 / 1024),
2) AS "Size in (MB)" FROM  information_schema.TABLES WHERE table_schema = "mylabdb"
ORDER
BY (data_length + index_length) DESC;




Finally, to find out the actual size of all MySQL database files on the disk (filesystem), run the
du command below.


sudo du -h /var/lib/mysql



Thursday, January 17, 2019

Linux How do I display failed login attempt?


/var/log/faillog is a log file for failed login attempts. This file maintains a count of login failures and the limits for each account. The file is fixed length record, indexed by numerical ID. Each record contains the count of login failures since the last successful login; the maximum number of failures before the account is disabled; the line the last login failure occurred on; and the date the last login failure occurred. Since data is in binary format you need to use faillog command to display failed login attempt.

faillog [options]

Options:
 -a, --all                     display faillog records for all users
 -h, --help                    display this help message and exit
 -l, --lock-secs SEC           after failed login lock account for SEC seconds
 -m, --maximum MAX             set maximum failed login counters to MAX
 -r, --reset                   reset the counters of login failures
 -R, --root CHROOT_DIR         directory to chroot into
 -t, --time DAYS               display faillog records more recent than DAYS
 -u, --user LOGIN/RANGE        display faillog record or maintains failure
                               counters and limits (if used with -r, -m,
                               or -l) only for the specified LOGIN(s)



How do I use faillog?

To display failed login attempt for user root with following command:
$ faillog -u root

Sample output

faillog -u root
Login       Failures Maximum Latest                   On

root            0 0 01/01/70 05:30:00 +0530  



To display all failed login attempt try:
$ faillog -a

faillog -a
Login       Failures Maximum Latest                   On

root            0 0 01/01/70 05:30:00 +0530  
daemon          0 0 01/01/70 05:30:00 +0530  
bin             0 0 01/01/70 05:30:00 +0530  
sys             0 0 01/01/70 05:30:00 +0530  
sync            0 0 01/01/70 05:30:00 +0530  
games           0 0 01/01/70 05:30:00 +0530  
man             0 0 01/01/70 05:30:00 +0530  
lp              0 0 01/01/70 05:30:00 +0530  
mail            0 0 01/01/70 05:30:00 +0530  
news            0 0 01/01/70 05:30:00 +0530  
uucp            0 0 01/01/70 05:30:00 +0530