blog.up-link.ro android bsd linux unix & open-source world

24Nov/111

UNIX Tips: How to find broken symbolic links

In computing, a symbolic link (also symlink or soft link) is a special type of file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution.

1. To display a list of the broken links, execute:

find -L ${dir} -type l

2. To remove the broken links, execute:

find -L ${dir} -type l -print0 | xargs -0 rm
Do not forget to replace ${dir} with the desired directory.

Print This Post Print This Post


27Oct/101

How To Monitor Network Traffic by Process under Linux

NetHogs is a small network monitoring tool. Instead of breaking the traffic down per protocol or per subnet, like most tools do, it groups bandwidth by process. NetHogs does not rely on a special kernel module to be loaded. If there's suddenly a lot of network traffic, you can fire up NetHogs and immediately see which process is causing this. This makes it easy to indentify programs that have gone wild and are suddenly taking up your bandwidth.

To install NetHogs under CentOS, Fedora, RHEL, enter:

yum install nethogs

To install NetHogs under Debian and Ubuntu, enter:

apt-get install nethogs

The default network interface to monitor is eth0. If you wish to use other device, simply type the argument after nethog, open the terminal and run the following command:

Print This Post Print This Post
17Oct/100

UNIX Tools: mytop – MySQL Monitoring Tool

MyTop is a console-based tool for monitoring the threads and overall performance of a MySQL server. It runs on most Unix systems. MyTop is a top clone for MySQL Server.

To install MyTop under FreeBSD, enter:

make install clean -C /usr/ports/databases/mytop

To install MyTop under CentOS, Fedora, RHEL, enter:

yum install mytop

To install MyTop under Debian, Ubuntu, enter:

sudo apt-get install mytop

Print This Post Print This Post
19Jul/100

UNIX Tools: tcpdump – packet analysis tool

tcpdump is a common network packet analyzer that runs under the command line. It allows the user to intercept and display packets being transmitted or received over a network to which the computer is attached. tcpdump is mandatory for anyone desiring a thorough understanding of TCP/IP.

tcpdump works on most Unix-like operating systems: BSD, Linux, Mac OS X, Solaris, HP-UX and AIX among others. In those systems, tcpdump uses the libpcap library to capture packets. There is also a port of tcpdump for Windows called WinDump and it uses WinPcap, which is a port of libpcap to Windows.

Print This Post Print This Post
18Jun/102

UNIX Tools: vmstat – report virtual memory statistics

vmstat is a computer system monitor tool that collects and displays summary information about operating system memory, processes, interrupts, paging and block I/O information.

vmstat

vmstat sample output

vmstat usage:

vmstat [-V] [-n] [delay [count]]

-V prints version.
-n causes the headers not to be reprinted regularly.
-a print inactive/active page stats.
-d prints disk statistics
-D prints disk table
-p prints disk partition statistics
-s prints vm table
-m prints slabinfo
-S unit size
delay is the delay between updates in seconds.
unit size k:1000 K:1024 m:1000000 M:1048576 (default is K)
count is the number of updates.

Print This Post Print This Post
3May/101

Unix-like Tips and Tricks: BASH Redirection

Bash is a POSIX shell with a number of extensions. It is the shell for the GNU operating system from the GNU Project. It can be run on most Unix-like operating systems.

In this article I'll talk about bash redirections.

Print This Post Print This Post
29Apr/100

UNIX-like Tips and Tricks: find command

The find program is a search utility on Unix-like operating systems. It searches through one or more directory trees of a filesystem, locating files based on some user-specified criteria. By default, find command returns all files below the current working directory. Further, find command allows the user to specify an action to be taken on each matched file. In this article I'll show you some tips for using the find command.

To begin, let's look at the basic structure of the find command:

find start_directory  test  options  criteria_to_match  action_to_perform

Example:

In the following command, find will search for any file with the "php" extension in the current directory:

# find . -name "*.php" -print

Print This Post Print This Post
26Apr/101

How To Change MAC Address in Linux, BSD, Unix

Media Access Control address (MAC address) is a unique identifier assigned to most network adapters or network interface cards (NICs) by the manufacturer for identification, and used in the Media Access Control protocol sub-layer. If assigned by the manufacturer, a MAC address usually encodes the manufacturer's registered identification number. It may also be known as an Ethernet Hardware Address (EHA), hardware address, adapter address, or physical address.

1. Change MAC Address in Linux ( CentOS, Debian, Fedora, RHEL, Slackware, SuSE, Ubuntu )

# ifconfig [interface name] down
# ifconfig [interface name] hw ether [new MAC address]
# ifconfig [interface name] up

Example:

# ifconfig eth0 down
# ifconfig eth0 hw ether 1A:2B:3C:4D:5E:6F
# ifconfig eth0 up

Print This Post Print This Post
30Mar/100

How To Backup MySQL databases using a shell script

MySQL is one of the most popular open source database management system for the development of interactive websites.

If your server stores its sensitive data in a MySQL database, you will most definitely want to backup that information so that it can be restored in case of any disaster.

Below is a backup script for MySQL databases (please make sure you will change MYSQL_PASS):

#!/bin/sh
# backup mysql databases shell script
# UNIX LINUX BSD
# by Adi http://blog.up-link.ro
# March 2010

DATE=$(date +%Y-%m-%d)
MYSQL=$(which mysql)
MYSQLDUMP=$(which mysqldump)
MYSQL_USER="root"
MYSQL_PASS="password"
HOSTNAME=$(hostname)
GZIP=$(which gzip)
ARG="-u $MYSQL_USER -p$MYSQL_PASS"
DATABASES=$($MYSQL $ARG -s -e "SHOW DATABASES;")
BACKUP_PATH="/home/backup/$DATE/mysql"

! [ -d $BACKUP_PATH ] && mkdir -p $BACKUP_PATH

for DB in $DATABASES
do
BACKUP_FILE="$BACKUP_PATH/$HOSTNAME-mysql-$DB-$DATE.sql.gz"
$MYSQLDUMP $ARG $DB | $GZIP -9 > $BACKUP_FILE
done

Download the script from here.

Print This Post Print This Post
24Mar/100

How To Reset MySQL Password

1. Stop MySQL server

# /usr/local/etc/rc.d/mysql-server stop

2. Start MySQL server  with skip grant table mode

# mysqld_safe –skip-grant-tables &
Output:
[1] 5187
# Starting mysqld daemon with databases from /var/db/mysql

3. Login as user root without password

# mysql -u root -p

Print This Post Print This Post