November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Linux common SHELL

Linux common SHELL 1 delete 0 byte file find -type f -size 0 -exec rm -rf {} \; 2. view the process Arranged in descending memory ps -e -o “% C:% p:% z:% a” | sort -k5 -nr Press the cpu utilization in descending order ps -e -o “% C:% p:% z:% a” | sort […]

Ksh Scripting

Principle of Script

Defining the Shell Type

To make a ksh script (which is a ksh program) crate a new file with a starting line like: #!/usr/bin/ksh It is important that the path to the ksh is propper and that the line doesn not have more than 32 characters. The shell from which you are […]

shell to get the process usage in MB

#!/bin/bash ps -A -o pid,rss,command | grep nginx | grep -v grep | awk ‘{total+=$2}END{printf(“nginx=%dMb\n”, total/1024)}’ ps -A -o pid,rss,command | grep php-fpm | grep -v grep | awk ‘{total+=$2}END{printf(“php-fpm=%dMb\n”, total/1024)}’ ps -A -o pid,rss,command | grep mysqld | grep -v grep | awk ‘{total+=$2}END{printf(“mysql=%dMb\n”, total/1024)}’ ps -A -o pid,rss,command | grep transmission-da | grep […]

LINUX MEMORY

Find Memory Usage

System memory used and free

Total Used and Free Memory in MBytes (in that order)

free -m|grep “buffers/cache”|cut -d”:” -f2 Memory by Process

Raw

ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS Human readable

ps -e -orss=,args= | sort -b -k1,1n | awk ‘{ split( “KB MB GB” , v […]

Bask quick learn

Bash Shell Shortcuts Special Shell Variables

Common environment variables

PATH – Sets the search path for any executable command. Similar to the PATH variable in MSDOS.

HOME – Home directory of the user.

MAIL – Contains the path to the location where mail addressed to the user is stored.

IFS – Contains a string […]

ZCAT Shell bash

How to display the contents of a gzip/gz file By Alvin Alexander. Last updated: Aug 6, 2011 Problem: You have a plain text file that has been compressed with the gzip command, and you’d like to display the file contents with the Unix/Linux cat or more commands.

Solution: Instead of using the cat or more […]

Grep, Awk, and Sed in bash

So, let’s consider the following log file:

www.three.com 10.15.101.11 1353280801 TEST 345 www.one.com 10.14.101.11 1353280801 TEST 343 www.three.com 1.10.11.71 1353280801 TEST 323 www.one.com 10.15.11.61 1353280801 TEST 365 www.two.com 10.10.11.51 1353290801 TEST 55 www.two.com 10.20.13.11 1353290801 REST 435 www.one.com 10.20.14.41 1353290801 REST 65 www.two.com 10.10.11.14 1353290801 REST 345 www.three.com 10.10.11.31 1354280801 REST 34 www.one.com 10.10.13.144 1354280801 […]

if condition-integer expression expected

if condition-integer expression expected

ADV1=94.3 Quantity=96.3 if [ $Quantity -eq $ADV1 ]; then echo “quantity is greter” fi

echo “” | nawk -v ADV1=94.3 -v Quantity=96.3 […]

Parsing – Logs

grep, cat, zgrep and zcat

More on log parsing, I’m taking notes on how to read log files and get the information that I need. On Linux environment, these tools are perfect: grep, cat, zgrep and zcat.

Extracting patterns with grep

We can extract information from a text file using grep. Example, we can extract […]

shell string comparison tests

shell string comparison tests Here are the operators for performing string comparison tests:

s1 Test if s1 is not the empty string s1 = s2 Test if s1 equals s2 s1 != s2 Test if s1 is not equal to s2 -n s1 Test if s1 has non-zero size -z s1 Test if s1 […]