August 2019
M T W T F S S
« Jul    
 1234
567891011
12131415161718
19202122232425
262728293031  

Categories

WordPress Quotes

Instead of worrying about what people say of you, why not spend time trying to accomplish something they will admire.
Dale Carnegie
August 2019
M T W T F S S
« Jul    
 1234
567891011
12131415161718
19202122232425
262728293031  

Short Cuts

2012 SERVER (64)
2016 windows (9)
AIX (13)
Amazon (40)
Ansibile (19)
Apache (135)
Asterisk (2)
cassandra (2)
Centos (211)
Centos RHEL 7 (268)
chef (3)
cloud (2)
cluster (3)
Coherence (1)
DB2 (5)
DISK (25)
DNS (9)
Docker (30)
Eassy (11)
ELKS (1)
EXCHANGE (3)
Fedora (6)
ftp (5)
GIT (3)
GOD (2)
Grub (1)
Hacking (10)
Hadoop (6)
health (1)
horoscope (23)
Hyper-V (10)
IIS (15)
IPTABLES (15)
JAVA (7)
JBOSS (32)
jenkins (1)
Kubernetes (7)
Ldap (5)
Linux (188)
Linux Commands (166)
Load balancer (5)
mariadb (14)
Mongodb (4)
MQ Server (24)
MYSQL (84)
Nagios (5)
NaturalOil (13)
Nginx (35)
Ngix (1)
openldap (1)
Openstack (6)
Oracle (35)
Perl (3)
Postfix (19)
Postgresql (1)
PowerShell (2)
Python (3)
qmail (36)
Redis (12)
RHCE (28)
SCALEIO (1)
Security on Centos (29)
SFTP (1)
Shell (64)
Solaris (58)
Sql Server 2012 (4)
squid (3)
SSH (10)
SSL (14)
Storage (1)
swap (3)
TIPS on Linux (28)
tomcat (62)
Uncategorized (30)
Veritas (2)
vfabric (1)
VMware (28)
Weblogic (38)
Websphere (71)
Windows (19)
Windows Software (2)
wordpress (1)
ZIMBRA (17)

WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

Who's Online

24 visitors online now
2 guests, 22 bots, 0 members

Hit Counter provided by dental implants orange county

Using Apache mod_jk with BigIP LTM and JBOSS

Using Apache mod_jk with BigIP LTM and JBOSS

Using Apache mod_jk with BigIP LTM and JBOSS

1) Make sure your JBOSS is running and listening on AJP port 8009

2) LTM Load Balancer Configuration
a) Create a TCP monitor jboss-tcp-monitor using parent profile TCP
b) Create a Virtual Server with port 8009
c) Create a Pool
d) Create a Pool member with port 8009. The member will be JBOSS server IP and port 8009
e) Associate Pool with jboss-tcp-monitor

3) Configure mod_jk in apache

Update these values to read as

worker.node1.port=8009
worker.node1.host={ltm-loadbalancer-vip}
worker.node1.type=ajp13

4) Test the browser website URL

Jboss with Apache integration

Jboss with Apache integration

Jboss Apache integration is same procedure of Tomcat Setup. 🙂 so they are not hard to so.

1) Download mod_jk module from

http://www.gtlib.gatech.edu/pub/apache/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.28/i586/

2) Copy mod_jk-1.2.28-httpd-2.2.X.so to /opt/apacheconf

3) Edit the httpd.conf and add the following line
Include /opt/apacheconf/mod-jk.conf

4) Create /opt/apacheconf/mod-jk.conf file with the following content
LoadModule jk_module /opt/apacheconf/mod_jk-1.2.28-httpd-2.2.X.so
JkWorkersFile /opt/apacheconf/workers.properties
JkLogFile /opt/apachelogs/mod_jk.log
JkLogLevel info
JkLogStampFormat “[%a %b %d %H:%M:%S %Y]”
JkOptions +ForwardKeySize +ForwardURICompatUnparsed -ForwardDirectories
JkRequestLogFormat “%w %V %T”

JkMountFile /opt/apacheconf/uriworkermap.properties
JkShmFile /opt/apachelogs/jk.shm


JkMount status
#Order deny,allow
#Deny from all
#Allow from 127.0.0.1

5) Create /opt/apacheconf/uriworkermap.properties file with the following content
# Simple worker configuration file
# Mount the Servlet context to the ajp13 worker
/jmx-console=loadbalancer
/jmx-console/*=loadbalancer
/web-console=loadbalancer
/web-console/*=loadbalancer
/testWeb/*=loadbalancer
!/testWeb/images/*=loadbalancer

6) Create /opt/apacheconf/workers.properties file with the following content
worker.list=loadbalancer,status
# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host={jboss-server-ip-address goes here}
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.prepost_timeout=10000 #Not required if using ping_mode=A
worker.node1.connect_timeout=10000 #Not required if using ping_mode=A
worker.node1.ping_mode=A #As of mod_jk 1.2.27
# worker.node1.connection_pool_size=10 (1)

# Define Node2
# modify the host as your host IP or DNS name.
#worker.node2.port=8009
#worker.node2.host= node2.mydomain.com
#worker.node2.type=ajp13
#worker.node2.lbfactor=1
#worker.node2.prepost_timeout=10000 #Not required if using ping_mode=A
#worker.node2.connect_timeout=10000 #Not required if using ping_mode=A
#worker.node2.ping_mode=A #As of mod_jk 1.2.27
# worker.node1.connection_pool_size=10 (1)

# Load-balancing behaviour
worker.loadbalancer.type=lb
#worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.balance_workers=node1

# Status worker for managing load balancer
worker.status.type=status

The above configuration is to test with one app server functionally.

7) Update /opt/apacheconf/httpd-vhosts.conf with JkMount
Listen 9080
NameVirtualHost *

ServerName {server-name}
ServerAlias {alias}
JkMount /testWeb loadbalancer
JkMount /testWeb/* loadbalancer

8) Update the following line to include jvmRoute in /opt/jboss-eap-5.0/jboss-as/server/default/deploy/jbossweb.sar/server.xml

9) Restart Apache and JBOSS server

10) Test the web server URL http://{domain-name}/testWeb/test.jsp

Jboss Linux Tuning

Jboss Linux Tuning

Linux Tuning Optimization

1) Commands to check current settings before updating sys parameters
———————————————————
cat /proc/sys/fs/file-max

ulimit -n

cat /proc/sys/net/core/rmem_default
cat /proc/sys/net/core/wmem_default
cat /proc/sys/net/core/rmem_max
cat /proc/sys/net/core/wmem_max

/sbin/ifconfig -a
eth0 Link encap:Ethernet HWaddr
inet addr: Bcast: Mask:
inet6 addr: fe80::250:56ff:febf:7f5a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9313376 errors:0 dropped:0 overruns:0 frame:0

cat /proc/sys/kernel/shmmax
cat /proc/sys/vm/nr_hugepages
———————————————————

2) Edit /etc/sysctl.conf and append these values
———————————————————
# Set File Max
set fs.file-max=102642

# Increase default socket send and receive buffers
net.core.rmem_default=262122

net.core.wmem_default=262122
net.core.rmem_max=262122
net.core.wmem_max=262122
———————————————————

3) Edit /etc/sysconfig/network-scripts/ifcfg-eth0 and append MTU
# recommended for gigabit ethernet to reduce packet fragmentation
MTU=9000

4) echo 2147483647 > /proc/sys/kernel/shmmax or update sysctl.conf
5) echo 1000 > /proc/sys/vm/nr_hugepages

6) Edit /etc/limits.conf and set ulimit value

Vi Editior

Vi Editior

How to copy data in VI editor

vi first edit source file
then move your cursor to start of selection
ma mark current position with letter a
then move your cursor to end of selection
y’a yank to buffer x from current position to mark a
:e other edit target file
move cursor to where you want the data
p put from buffer x

Copying a block of text from one file to another in Vi
December 29th, 2008 No comments

To copy a block of text between files execute the commands:
Command Explaination
1. Edit the file containing the text you want to copy.
2. Go to the top line to be copied.
3. ma Mark this line as mark “a”.
4. Go to the bottom line to be copied
5. y’a Yank (y) the text from the current cursor location to the mark “a” (‘a)
6. :split second-file Open another window containing the second file. (This the file in which the text is to be inserted.)
7. Go to the line where the insert is to occur. The text will be place after this line.
8. p Put the text after the cursor.

For Vi Editor
Do you like www.linuxnix.com ? Please consider supporting us by becoming a subscriber and get a Linux basics e-book for free.
unix_vi_editor

VI editor is the default file editor in most of the Linux/Nix machines. It is having great capabilities to edit a file with in few key strokes.

Lets start with some general information and then move on to some good things what vi editor can do for you while editing a file.
1. Vi stands for visual.
2. Vi have its variants like vim which stands for Vi IMproved, VimX11 for gui and winvi for MS windows.
3. Vi is the most popular editor and next most popular editor is gedit.
4. Do you know there is a book on VI editor from orally which is of 600+ pages.
5. Some other editors which will do the work of editing files are neno, pico, gedit, emacs, joe, nedit, ed etc.

Learning vi editor and remembering them is a very a easy task if you learn it in a systematic way.
a. Modes of VI
b. Navigational commands
c. Editing commands.
d. Search and Replace
e. Save and quiting a file.

a. Modes of VI :
Vi have two mode of operation.
1. Command mode
2. Inserting mode

Command mode :
Vi editor begins in command mode, where cursor movement(navigation in the file) and editing occur. To enter in to command mode from Inserting mode press esc button.

Inserting mode :
Used for entering text, this is similar to notepad in Windows. To enter in to inserting mode you can use any of the following.
i or I => present line
o => one line down the present line
O => one line above

Note : All comments will work in command mode only.

b. Navigational commands :
1. Character navigation k, h, l and j
h => To move one character left.
j => To move one line down.
k => To move one line up.
l => To move one character right.

How to use above commands in clever way?
Examples :
6j => to move 6 lines down from the present courser.
7k => to move 7 lines above from the present courser.

2. Word Navigation
w => word forward.
e =>word forward, but end of the word.
b => one word backward.

Examples :
32w => To move 32 words forward
6b => To move 6 words back.

3. Setting (nu) mbering to lines
:set nu
Removing of (nonu)mbering to lines
:set nonu

4. Moving paragraphs
move one paragraph up => {{
move one paragraph down => }}

5. Moving page up/down
For up => ctrl+b
For down => ctrl+f

6. Moving start/end of the file
Starting of the file(first line => [[
End of the file(last line) => ]]

7. Going to any line :
:lineno

Example :
If we want to go to 56 line then type
:56

c. Editing commands

8. Replace one letter
Replace one letter => r
Delete one letter => x

>9. Editing one word
Edit one word => cw
Delete one word => dw

10. Editing one line
Editing a line from courser to the end of that line => d$

11. Cutting
deleting(cutting) one line => dd

Examples :
2dd(deleting/cutting two lines)

12. Pasting
Pasting a line below the courser => p
Pasting a line above the courser => P

13. Coping
Copying one line => yy
Copying n lines => nyy

14. Special commands
joining lines => J
undoing things => u
repeating previous command => .

d. Search and replace

15. Search for a term /term

Example : If you want to search for suresh then press /suresh enter
/suresh
Moving to next occurrence, press “n” with out quotes moving to previous occurrence, press “N” with out quotes.

16. Searching and replacing a term(here separator is / )
:%s/searchterm/replaceterm/g
change default separator
:%s_/home/surya/grade_/home/testing/dest_g

To search and replace particular term from given line to other given line.
:%s294,304/sahana/xyz/g

e)Save and quiting a file
:w => save the file
:q => quit the file
:wq => save and quit
:w! => force save the file
:q! => force quit with out save
:wq => save and quit forcefully

Memory commands

Memory commands

How do I find out System / Server Memory Utilization under RHEL / CentOS / any other Linux distribution?

A. You need to use free command which, displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.
free command example

Type the free command at shell prompt:
$ free
$ free -m
Output:

total used free shared buffers cached
Mem: 2010 1965 45 0 152 776
-/+ buffers/cache: 1036 974
Swap: 2047 137 1910

vmstat command

vmstat command provides more information :
$ vmstat
Output:

procs ———–memory———- —swap– —–io—- –system– —–cpu——
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 140480 43636 158196 797692 1 0 108 220 1 4 7 5 87 1 0

Understanding vmstat memory options

* swpd: the amount of virtual memory used.
* free: the amount of idle memory.
* buff: the amount of memory used as buffers.
* cache: the amount of memory used as cache.
* inact: the amount of inactive memory. (-a option)
* active: the amount of active memory. (-a option)

$ vmstat -a
Output:

procs ———–memory———- —swap– —–io—- –system– —–cpu——
r b swpd free inact active si so bi bo in cs us sy id wa st
0 1 140480 37376 109516 1730040 1 0 108 220 1 4 7 5 87 1 0

The following command displays one new line of utilization data every second
$ vmstat 1
The following command displays one new line per 2 second, but only for the next 10 seconds:
$ vmstat 2 10
Output:

procs ———–memory———- —swap– —–io—- –system– —–cpu——
r b swpd free inact active si so bi bo in cs us sy id wa st
4 0 139216 23508 130644 1723680 1 0 108 220 1 5 7 5 87 1 0
2 0 139216 23252 130668 1723816 0 0 0 410 3242 11472 9 7 84 0 0
1 0 139216 23120 130656 1724012 0 0 0 750 3280 11592 3 6 90 1 0
0 0 139216 22996 130588 1724180 0 0 0 426 3272 11052 2 5 93 0 0
2 0 139216 20988 129932 1726980 0 0 6 1146 3353 12105 14 9 74 2 0
1 0 139216 20244 129900 1727216 0 0 0 392 3238 11752 8 7 85 0 0
1 0 139216 20120 129868 1727352 0 0 0 444 3197 11173 2 5 93 0 0
1 0 139216 25964 129852 1721044 0 0 0 268 3147 9269 1 4 95 0 0
3 0 139216 25964 129748 1721196 0 0 2 132 3199 10540 1 4 95 0 0
1 0 139216 25964 129676 1721332 0 0 0 456 3213 10608 2

Free Memory on Linux at Runtime
sync
echo 3 > /proc/sys/vm/drop_caches

Display Only The Process IDs of Lighttpd

ps -C lighttpd -o pid=
OR
pgrep lighttpd
OR
pgrep -u vivek php-cgi
Display The Name of PID 55977

ps -p 55977 -o comm=

CPU COMMAND

CPU COMMAND

PU COMMAND

10 cpu usage command

ps -e -o pcpu,cpu,nice,state,cputime,args –sort pcpu | sed ‘/^ 0.0 /d’

####Watch changeable data continuously

watch -n.1 ‘cat /proc/interrupts’

cat /proc/interrupts

Check CPU Temperature
# echo `date +%b-%d-%H:%M:%S` | tr -d ‘\ 012’ ; echo -n ‘ ‘; sensors | awk ‘/CPU Temp:/{ print $3 }’

Check those commands which have been used most
# history|awk ‘{print $2}’ |awk ‘{print $1}’ | sort | uniq -c | sort -rn | head -10

Linux System Monitoring Commands

Linux System Monitoring Commands

#1: top – Process Activity Command

Commonly Used Hot Keys

The top command provides several useful hot keys:
Hot Key Usage
t Displays summary information off and on.
m Displays memory information off and on.
A Sorts the display by top consumers of various system resources. Useful for quick identification of performance-hungry tasks on a system.
f Enters an interactive configuration screen for top. Helpful for setting up top for a specific task.
o Enables you to interactively select the ordering within top.
r Issues renice command.
k Issues kill command.
z Turn on or off color/mono

What are the CPU states found in “top” output?
Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

# us -> User CPU time: The time the CPU has spent running users’ processes that are not niced.
# sy -> System CPU time: The time the CPU has spent running the kernel and its processes.
# ni -> Nice CPU time: The time the CPU has spent running users’ process that have been niced.
# wa -> iowait: Amount of time the CPU has been waiting for I/O to complete.
# hi -> Hardware IRQ: The amount of time the CPU has been servicing hardware interrupts.
# si -> Software Interrupts.: The amount of time the CPU has been servicing software interrupts.

#2: vmstat – System Activity, Hardware and System Information

The command vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity.

vmstat 3

Display Memory Utilization Slabinfo

# vmstat -m

Tail, Vmstat and Date in Loop, Output every 10 Sec
# vmstat 1 1;for ((;;));do date; vmstat 10 2 | tail -n1;done

3: w – Find Out Who Is Logged on And What They Are Doing

w command displays information about the users currently on the machine, and their processes.
# w username
# w vivek

#4: uptime – Tell How Long The System Has Been Running

# uptime

#5: ps – Displays The Processes

Show Long Format Output

# ps -Al

Print All Process On The Server

# ps ax
# ps axu

Memmory commands cpu commands

Print Security Information

# ps -eo euser,ruser,suser,fuser,f,comm,label

Set Output In a User-Defined Format

ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm

ps -eopid,tt,user,fname,tmout,f,wchan

Display sorted process taking most CPU in descending order
# ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

Grep Command

Grep Command

some examples of grep command:

* Print Apache’s documentroot directory name:

$ grep -i documentroot /etc/httpd/conf/httpd.conf

* View file contents without comments and empty lines:

$ grep -Ev “^$|^#” /etc/my.cnf

* print only IP address assigned to the interface:

$ ifconfig eth0 | grep ‘inet addr:’ | cut -d’:’ -f2 | awk ‘{ print $1}’

* How many email messages sent for a particular date:

$ cat /var/log/maillog | grep “status=sent” | grep “May 25” | wc -l

* Find out a running process/daemon from process list (thanks to staranneph for recalling this):

ps -ef | grep mysql

* You can also note cpu/mem usage by using above. like in below command output, you can see that Plesk’s statistics process is utilizing more than 18% cpu alone:

[root@myserver ~]# ps aux | grep statistics
root 8183 18.4 0.0 58384 2848 ? D 04:05 3:00 /usr/l

FIND Command

FIND Command

Find is a versatile tool which can be used to locate files and directories satisfying different user criteria. But the sheer number of options for this command line tool makes it at the same time both powerful and encumbering for the user. Here I will list a few combinations which one can use to get useful results using find command.

f – file
d – directory
l – symbolic link
c – character
p – named pipe (FIFO)
s – socket
b – block device

Find all HTML files starting with letter ‘a’ in your current directory (Case sensitive)
find . -name a\*.html

Same as above but case insensitive search.
find . -iname a\*.html

Find files which are larger than 5 MB in size.
find . -size +5000k -type f

Here the ‘+’ in ‘+5000k’ indicates greater than and k is kilobytes. And the dot ‘.’ indicates the current directory. The -type option can take any of the following values:

… Which is all files with 0 bytes size. The option -size can take the following:

c – bytes
w – 2 byte words
k – kilo bytes
b – 512 byte blocks

Note: The above command can also take the -empty parameter.

Find is very powerful in that you can combine it with other commands. For example, to find all empty files in the current directory and delete them, do the following:
find . -empty -maxdepth 1 -exec rm {} \;

To search for a html file having the text ‘Web sites’ in it, you can combine find with grep as follows:
find . -type f -iname \*.html -exec grep -s “Web sites” {} \;

… the -s option in grep suppresses errors about non-existent or unreadable files. And {} is a placeholder for the files found. The semicolon ‘;’ is escaped using backslash so as not to be interpreted by bash shell.

Note: You can use the -exec option to combine any command in Linux with the find command. Some of the useful things you can do with it are as follows:

Compress log files on an individual basis
find /var -iname \*.log -exec bzip {} \;

Find all files which belong to user lal and change its ownership to ravi
find / -user lal -exec chown ravi {} \;

Note: You can also use xargs command instead of the -exec option as follows:
find /var -iname \*.log | xargs bzip –

Find all files which do not belong to any user:
find . -nouser

Find files which have permissions rwx for user and rw for group and others :
find . -perm 766

… and then list them.

find . -perm 766 -exec ls -l {} \;

Find all directories with name music_files
find . -type d -iname \*music_files\*

Suppose you want to find files of size between 700k and 1000k, do the following:
find . \( -size +700k -and -size -1000k \)

And how about getting a formatted output of the above command with the size of each file listed ?
find . \( -size +700k -and -size -1000k \) -exec du -Hs {} \; 2>/dev/null

… here, the ‘2>/dev/null’ means all the error messages are discarded or suppressed.

You can also limit your search by file system type. For example, to restrict search to files residing only in the NTFS and VFAT filesystem, do the following:
find / -maxdepth 2 \( -fstype vfat -or -fstype ntfs \) 2> /dev/null

To View Or List Only Directories In Linux?
Do you like www.linuxnix.com ? Please consider supporting us by becoming a subscriber and get a Linux basics e-book for free.

How to view/list only directories in Linux?
Ans : This can be achieved in two ways
1. Through ls command
2. Through find command

With ls we have to use grep to get the directory listings.
Ls –l grep ^d

Example :
[root@test rmohan_a]# ls -l grep ^d
d——— 2 rmohan_a rmohan_a 4096 Sep 8 09:54 HTWFAIP
drwxrwxr-x 2 rmohan_a root 4096 Nov 27 12:30 LinuxCBT – RHEL5
drwxrwxr-x 2 rmohan_a root 4096 Oct 12 16:40 Software
[root@test rmohan_a]#

With find we can have more controle on how to display only directories.

A. To display all the directories and sub-directories in present directory
#find . -type d

B. Displaying only directories in present directory
#find /root/ -type d –maxdepth 1

C. Displaying just directories in present directry and its sub-directories
#find /root/ -type d –maxdepth 2

* find top 10 largest files in /var:

$ find /var -type f -ls | sort -k 7 -r -n | head -10

* find all files having size more than 5 GB in /var/log/:

$ find /var/log/ -type f -size +5120M -exec ls -lh {} \;

* find all today’s files and copy them to another directory:

$ find /home/me/files -ctime 0 -print -exec cp {} /mnt/backup/{} \;

* find all temp files older than a week and delete:

$ find /temp/ -mtime +7-type f | xargs /bin/rm -f

* find and rename all mp3 files by changing their uppercase names to lowercase:

$ find /home/me/music/ -type f -name *.mp3 -exec rename ‘y/[A-Z]/[a-z]/’ ‘{}’ \;

find mtime

find . -mtime 0 # find files modified between now and 1 day ago
# (i.e., within the past 24 hours)
find . -mtime -1 # find files modified less than 1 day ago
# (i.e., within the past 24 hours, as before)
find . -mtime 1 # find files modified between 24 and 48 hours ago
find . -mtime +1 # find files modified more than 48 hours ago

find . -mmin +5 -mmin -10 # find files modified between
# 6 and 9 minutes ago

Find Parameters

-daystart This flag starts at the beginning of the day.
-atime The time the file was last accessed — in number of days.
-ctime The time the file’s status last changed — in number of days.
-mtime The time the file was last modified — in number of days.
-amin The time the file was last accessed — in number of minutes. (It is not available on all implementations.)
-cmin The time the file’s status last changed — in number of minutes. (It is not available on all implementations.)
-mmin The time the file was last modified — in number of minutes. (It is not available on all implementations.)
-type This flag describes the type of file, such as d for directories.
-userX Files belonging to user X.
-groupX Files belonging to group X.
-newerX Files that are newer than file X.

Here’s how to list all the files in your home directory tree that were modified exactly one hour ago:$ find ~ -mmin 60 \! -type d

Giving a negative value for a flag means to match that number or sooner. For example, here’s how to list all the files in your
home directory tree that were modified exactly one hour ago or any time since

find ~ -mmin -60 \! -type d

$ date
Mon Oct 23 09:42:42 EDT 2006
$ touch -t 10230842 temp
$ ls -l temp
-rw-r–r– 1 joe joe 0 Oct 23 08:42 temp
$ find ~ -newer temp \! -type d

find / -user `whoami` -daystart -atime -1 \! -type d

Give different values for the various time flags to change the search times. You can also combine flags. For instance,
you can list all the files in your home directory tree that were both accessed and modified between now and seven days ago:
find ~ -daystart -atime -7 -mtime -7 \! -type d

find /home/$1/mail/*/mail/.spam/cur -type f -mtime +7 -exec rm {} \;
find /home/$1/mail/*/mail/.spam/new -type f -mtime +7 -exec rm {} \;
find . -type f -exec grep ‘NMX_FXNG_AND_CONTRACT_DBF’ {} \;

Delete Empty Directories
# find folder/ -type d -empty | xargs -i -t rm -rf {}
or
# find folder/ -type d -empty -delete

DISK SPACE COMMAND

Find files based and sorted on Size
# find / -type f -size +20000k -exec ls -lh {} \; 2> /dev/null | awk ‘{ print $NF “: ” $5 }’ | sort -nrk 2,2

MYSQL Back On Unix

MYSQL Back On Unix

Shell script is a script where we are writing different types of commands and executing those commands from a single file. We can execute that command manually, by entering command one by one. But if we use shell script we have to write those commands into a text file for the first time and then we can run those commands as many times as required.

In this article first I will show you, Complete Script. Later on, you will get a description of that script. I assumed that you know about shell scripting, mysqldump and crontab.

Operating System: Any Linux or UNIX.

Main Script (for backup your mysql database):

This shell script will make the backup process of a database automatic. Just copy and paste this script in a text editor, put database user name, password, and database name. I will use mysqlump command to backup the database. Later on you will get description of each line.
1. Make a directory name “backup” and “oldbackup”
1
2

mkdir /backup
mkdir /oldbackup
2. Now make file name “backup.sh” and edit with any editor you like

I’m using vi here-
1

# vi /backup/backup.sh

Now write these lines into backup.sh file:
#!bin/bash
cd /backup
echo “You are In Backup Directory”
mv backup* /oldbackup
echo “Old Databases are Moved to oldbackup folder”
Now=$(date +”%d-%m-%Y–%H:%M:%S”)
File=backup-$Now.sql
mysqldump –u user-name –p ‘password’ database-name > $File
echo “Your Database Backup Successfully Completed”

Script Description:

Remember, in line number 8: Put your Database username, Password, database name after mysqldump command.

When we run this script, first it goes to a /backup directory. Then it will move old database backup files to /oldbackup folder. Next it generates a file name from system date and time. And finally mysqldump command will generate a database backup file with “.sql” format
3. Set permission to backup.sh file executable
1

# chmod +x /backup/backup.sh
4. Running the Script
1

#./backup.sh

You will get following output after executing the script.
root@Server1:/download#./backup.sh
You are in Download Directory
Old Backup Database is Moved to oldbackup folder
database backup successful completed
root@Server1:/download#

NB: first time when you run this script you will get a message “no such file”, because you don’t have old backup file. No problem just runs again this script, problem will be solved.
5. Schedule the Backup using cron

Using Cron job you can execute this script in a certain time, and all works will be done automatically. Use crontab command to edit editing cron schedules.

#crontab –e

Just add below line in the editor and save it.
0 13 * * * * /backup/backup.sh

In this way every day 1PM your database will back up in your desired folder. Please visit crontab manuals for more details about setting the cron jobs.

This is a very basic script for the beginners. Hope you can use the same idea for more complex backup. We will try to come up with new scripts to automate further. Please ask any question you have. We will try our best to address your questions. Thanks for staying with us.

No related posts.