How To Write Infinite Loop in Bash

This is how you create an infinite loop in bash to run a piece of code infinitely at defined intervals.


#!/bin/bash
while [ 1 ]
do
# Your code goes here

# Modify sleep time (in seconds) as needed below
sleep 2
done

I needed such code to monitor the size of a file every 2 seconds.

Source: http://blog.taragana.com/index.php/archive/how-to-write-infinite-loop-in-bash/

Tagged | Leave a comment

find files and copy them to a certain folder in bash (draft)

find . -name “*” | grep -i scomm | xargs ls -ltr | grep “Aug 13 10” | awk ‘{print $9}’

to use in the cp command (get the column number 9 which contains the file’s full path

cp `find . -name “*” | grep -i scomm | xargs ls -ltr | grep “Aug 13 10” | awk ‘{print $9}’` /sfs/aamr/scomm/sbprd02

If the search_string contains any special characters (e.g. dot, slash, double quotations …etc, then preceed it by a ‘\’

Tagged , , | Leave a comment

How to search for a string inside multiple text files

find starting_folder -name “*” | grep -i file_name | xargs grep -i search_string

for example:

“find . -name “*” | grep -i hobba | xargs grep -i tito”

searches for the string “tito” inside all files whose name contains the word “hobba” inside the current folder.

Note that the “-i” parameter for the “grep” command makes the search case insensitive.

Tagged , , | Leave a comment

How to search for a file using the "find" command in bash (not case sensitive)

find start_directory -name “*” | grep -i search_string

e.g. “find . -name “*” | grep -i hobba” searches within the current directory and can return a file with name “aamr_HoBba.log” for example.

Tagged , | Leave a comment

An Introduction to linux Shell Scripting for DBAs, A Nice Tutorial by Oracle

I found this nice tutorial and would like to share it with you, it’s really useful:

http://www.oracle.com/technology/pub/articles/saternos_scripting.html

Tagged , | Leave a comment