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  

ls

I always find it difficult to digest the filesize from the ls -al command. For instance, after ls -al, the output give me filesize in bytes.

Gosh, then I have to start calculating it by taking last 4 digits, slowly count upwards like 1K, 10K, 100K, 1MB, 10MB, 100MB and so on so forth.

For […]

find shell

Find files larger than 100MB…

find . -size +100000000c -ls Old Files Find files last modified over 30days ago…

find . -type f -mtime 30 -ls Find files last modified over 365days ago…

find . -type f -mtime 365 -ls Find files last accessed over 30days ago…

find . -type f -atime 30 -ls Find […]

Shell good reference

The Bourne shell (/bin/sh) is present on all Unix installations and scripts written in this language are (quite) portable; man 1 sh is a good reference. Basics

Variables and arguments

Assign with variable=value and get content with $variable MESSAGE=”Hello World” # Assign a string PI=3.1415 # Assign a decimal number N=8 TWON=`expr $N * 2` […]

Date and time calculation functions using AWK

awk has 3 functions to calculate date and time: systime strftime mktime Let us see in this article how to use these functions:

systime: This function is equivalent to the Unix date (date +%s) command. It gives the Unix time, total number of seconds elapsed since the epoch(01-01-1970 00:00:00). $ echo | awk ‘{print systime();}’ […]

awk

USAGE

Unix: awk ‘/pattern/ {print “$1”}’ # standard Unix shells DOS/Win: awk ‘/pattern/ {print “$1”}’ # okay for DJGPP compiled awk “/pattern/ {print \”$1\”}” # required for Mingw32 Most of my experience comes from version of GNU awk (gawk) compiled for Win32. Note in particular that DJGPP compilations permit the awk script to follow Unix […]

Function in shell script

Function in shell script DESCRIPTION: Function is the piece of code, which executed when we call. When thinking about the function in any computer language, three points comes in mind

1. Writing function code and calling that function when we need 2. Passing arguments to the function 3. Returning value from function

Next i […]

bash printf to variable

If you want to use bash’s printf formatting and store the value into a variable, you can use bash’s print’s -v flag as follows:

calc_elaspsed_time() { local SECONDS=$1 ((h=SECONDS/3600)) ((m=SECONDS%3600/60)) ((s=SECONDS%60)) printf -v ELAPSED_TIME “%02d:%02d:%02d” $h $m $s }

printf Command The built-in printf (print formatted) command prints a message to the screen. You […]

Function in shell script

Function in shell script DESCRIPTION: Function is the piece of code, which executed when we call. When thinking about the function in any computer language, three points comes in mind

1. Writing function code and calling that function when we need 2. Passing arguments to the function 3. Returning value from function

Next i […]

Command line argument in shell script

Command line argument in shell script Passing arguments to the main program when it start is know as command line arguments In shell scripting arguments can be described like below

$0 – shows program name which you running $1 – shows first argument $2 – display second argument $3 – display third argument $n – […]

check httpd runing or not

#!/bin/sh SERVICE=’httpd’

if ps ax | grep -v grep | grep $SERVICE > /dev/null then echo “$SERVICE service running, everything is fine” else echo “$SERVICE is not running” echo “$SERVICE is not running!” | mail -s “$SERVICE down” root fi