Bash: No space left on device

If you get this error on your Linux web server: -bash: No space left on device-bash: No space left on device That probably means you ran out of inodes, type this to check: df -idf -i If you see something like this: Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda2 1310720 1310720 0 100% /Filesystem […]

Bash Script to Delete PHP Session Files and Free Inodes

Use “df -i” command to view inodes usage: Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda2 1310720 1310720 0 100% /Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda2 1310720 1310720 0 100% / That means you ran out of inodes! Most probably PHP sessions are the issue. A quick command to delete all sess_* files […]

Regex Remove Blank Lines from Text in PHP

This regex will remove (preg_replace) all empty new lines from a text: $str = preg_replace(‘/^\n+|^[\t\s]*\n+/m’, ”, $str);$str = preg_replace(‘/^\n+|^[\t\s]*\n+/m’, ”, $str);

Force Overwrite Files with Cp on Linux

Command to force “cp” to copy and overwrite files without confirmation: Call “cp” directly to prevent it from using the aliased version: /bin/cp -rf /source/* /destination/bin/cp -rf /source/* /destination Or use “yes” to auto-reply with “y” to confirmation: yes | cp -rf /source/* /destinationyes | cp -rf /source/* /destination

Netstat Count Active ESTABLISHED Connections

Count all active ESTABLISHED connections: netstat -anp | grep ESTABLISHED | wc -lnetstat -anp | grep ESTABLISHED | wc -l Count all active ESTABLISHED connections on port 80: netstat -anp | grep :80 | grep ESTABLISHED | wc -lnetstat -anp | grep :80 | grep ESTABLISHED | wc -l Count all active ESTABLISHED connections on […]

Copy Files Preserving Timestamps on Linux

You can use the parameter “-p” to preserve timestamps and modification date: -p same as –preserve=mode,ownership,timestamps-p same as –preserve=mode,ownership,timestamps Recursively (-R) copy a folder maintaining modification time (-p): cp -Rp folder destinationcp -Rp folder destination Copy all .log files maintaining modification time: cp -p *.log destinationcp -p *.log destination More information: http://www.unix.com/man-page/Linux/1/cp/

Javascript Get Window Location Hostname

Various example demonstration how to get URL on the address bar using Javascript, which include location.hostname, window.top.location, window.location.origin, and more. In the example below I included also an example to remove the www. from the website address. Here is the script code to get various locations with Javascript var x = location.hostname; document.getElementById("demo1").innerHTML= x; var […]

Bash Script to Get Website IP Address

Simple bash script to get IP address of a website: #!/bin/bash # Usage: ./script google.com ip="$(/usr/bin/dig A $1 +short)" echo $1 = $ip#!/bin/bash # Usage: ./script google.com ip="$(/usr/bin/dig A $1 +short)" echo $1 = $ip Example output: root@server:~# ./getip.sh google.com google.com = 172.217.16.78root@server:~# ./getip.sh google.com google.com = 172.217.16.78

RAID1 vs RAID5 IOPS Write\Read Speed Benchmark

Here is a simple RAID1 vs RAID5 IOPS write\read speed benchmark test: RAID5 (3x120GB SSD) The server has the following characteristics: 2 x Intel Xeon E5 2620 12C/24T @2,00 GHz 3x120GB SSD (RAID5) 128GB RAM DDR32 x Intel Xeon E5 2620 12C/24T @2,00 GHz 3x120GB SSD (RAID5) 128GB RAM DDR3 The RAID controller type and […]

Rotate Nginx Logs and Append Date and Time

I needed to rotate Nginx logs and append the date and time, i.e: access.log => access.log-25-02-2017access.log => access.log-25-02-2017 So instead of adding a number like access.log.1 I need to add date. Here are two solutions that can be used: Use a custom bash script Here is a simple bash script that can do the work: […]