Thanks to antville.org
shell script example

An example of shell script.
This will print numbers 0 to 500 in one line.

!/bin/bash

Z=0
LIMIT=500
while [ "$Z" -lt "$LIMIT" ]

do
echo -n "$Z... "
Z=$( expr $Z + 1 )
done
echo
exit 0


ping the address received from positional parameter

!/bin/bash

if [ $# -eq 0 ]
then
SITE="google.com"
else
SITE="$1"
fi

ping -c 2 $SITE > /dev/null
if [ $? != 0 ]
then
echo $(date +%F) ... Network Failure!
fi


Here is the script that will loop two thousand times and print the statement on the screen.

!/bin/sh

MAX=2000
i=1
echo " truncate table t1; "

while [ $i -le $MAX ]
do
echo " insert into t1(f1) values($i); "
i=expr $i + 1
done

... Link (0 comments) ... Comment


Match Operator in AWK

The match operator is the tilde “~” which will match an expression in a record or field. In this example awk is used to search for a field, number 7, that matches “nologin”.

awk -F: '$7 ~ /nologin/' /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin

... Link (0 comments) ... Comment


Copy table

!/bin/sh

for i in find /var/lib/mysql/test/ -name "Table1.*"
do
cp $i dirname $i'/test'basename $i
done

duplicate a table Table1 by coping the files if it is a MyISAM table.

... Link (0 comments) ... Comment


Inernal File Separator

The safe way to change IFS in a 'while read' loop is:

while IFS=| read a b c
do
: whatever
done

... Link (0 comments) ... Comment


valid date

validdate.sh script will look like this...

!/bin/sh

userdate=$1
date -d $userdate &> /dev/null
if [ $? -ne 0 ] ; then
echo You entered an invalid date, $userdate
else
echo The date $userdate is valid
fi

sh validdate.sh 2009-33-44

You entered an invalid date, 2009-33-44

... Link (0 comments) ... Comment


Backup a directory

!/bin/sh

tar czvf $1.$(date +%Y%m%d-%H%M%S).tgz $1
exit $?

The arc script accepts a single file or directory name as a parameter and creates a compressed archive file with the current date embedded into the resulting archive file's name.

... Link (0 comments) ... Comment


better code

test -s /var/log/mailme.txt
if [[ $? -eq 0 ]] ; then
The above 2 lines can be written in one line as shown below:

if [[ -z /var/log/mailme.txt ]]; then

... Link (0 comments) ... Comment


read .csv file

!/bin/sh

awk -F"," '{print $1,$2}' read1.txt | while read var1 var2
do
echo $var1 $var2
done

... Link (0 comments) ... Comment


findtable shell script

vi /bin/findtable

!bin/sh

mysql -e"select TABLE_SCHEMA, TABLE_NAME, ENGINE, TABLE_ROWS, CREATE_TIME FROM information_schema.TABLES where TABLE_NAME LIKE '%$1%';"

chmod 777 /bin/findtable

sh findtable test

... Link (0 comments) ... Comment


Online for 6268 days
Last modified: 10/22/19 2:54 AM
Status
Youre not logged in ... Login
Menu
... Home
... Tags

Search
Calendar
October 2019
SunMonTueWedThuFriSat
12345
6789101112
13141516171819
20212223242526
2728293031
September
Recent updates
This is nice. At least
I've found a nice blog like this... Worth reading....
by casseverhart13 (10/22/19 2:54 AM)
check out the new
stuff you post in the future! magician Philadelphia
by casseverhart13 (10/21/19 5:03 AM)
Hope to read another
kind of article like this. pressure washing Gainesville
by casseverhart13 (10/18/19 4:35 AM)
Real Human Website Traffic -
The short answer is that it is #traffic that...
by webvisitors (10/17/19 10:01 PM)
Great! Thanks for sharing your
post, it seems really interesting to read. I hope to...
by Anna0203 (10/17/19 7:32 PM)
Great Thanks for posting this
one. :) commercial window cleaning cincinnati ohio
by brielleluna (10/17/19 7:27 PM)
Nice Since then, I always
check your article because it was really an informative one....
by Meggy27 (10/17/19 3:52 PM)
I hope you continue
writing about this kind of entry. carpet steam cleaner
by casseverhart13 (10/17/19 10:15 AM)
It's my pleasure to find
this amazing website who provides mostly unseen information about...
by casseverhart13 (10/17/19 5:26 AM)
Did you know that many
company Buy Website Traffic that is driven to their...
by webvisitors (10/17/19 2:28 AM)
USA State Targeted Traffic you
can isolate marketing efforts with a specific state, or...
by webvisitors (10/17/19 1:20 AM)
Want to work with a
reputable company with countless return customers? Talk to us...
by webvisitors (10/17/19 1:19 AM)
Weekly Email Notification enable Weekly
Email Notification from the Trusted Advisor. 1) Open the AWS...
by shantanuo (10/16/19 3:14 PM)
If most of your customers
are from Texas, don't waste time and money marketing...
by webvisitors (10/15/19 5:52 PM)
Buy Website Traffic - Expand
your reach! Give prospects nationwide exposure to your products...
by webvisitors (10/15/19 5:47 PM)
I hope you continue
writing about this kind of entry. Tree Solutions Hunter's Creek
by casseverhart13 (10/15/19 11:19 AM)
Great blog you have here
but I was wondering if you knew of any...
by casseverhart13 (10/15/19 5:17 AM)
Buy Website Traffic - Expand
your reach! Give prospects nationwide exposure to your products...
by webvisitors (10/15/19 12:43 AM)
Buy Website Traffic - Expand
your reach! Give prospects nationwide exposure to your products...
by webvisitors (10/15/19 12:42 AM)
Buy Website Traffic - Expand
your reach! Give prospects nationwide exposure to your products...
by webvisitors (10/15/19 12:42 AM)
Buy Website Traffic - Expand
your reach! Give prospects nationwide exposure to your products...
by webvisitors (10/15/19 12:42 AM)
Buy Website Traffic - Expand
your reach! Give prospects nationwide exposure to your products...
by webvisitors (10/15/19 12:41 AM)
Buy Website Traffic - Expand
your reach! Give prospects nationwide exposure to your products...
by webvisitors (10/15/19 12:41 AM)
Targeted Web Traffic If you
want the best, come to the best! Based in the...
by webvisitors (10/15/19 12:31 AM)
Prevol Financiera However, this method
of cashless electronic payment transaction has strings attached in terms...
by saeedkhatri (10/14/19 8:33 AM)

RSS feed

Made with Antville
Helma Object Publisher