Archive for May, 2009

SBDavid

Using Find Linux Command.

The find command plays an integral part in some of the most important scripts that are used in any Linux system.

Find Linux Command.

* Find can search for files in a directory hierarchy.

More about the find command.

By default, find returns all files below the current working directory. Further, find allows the user to specify an action to be taken on each matched file.

The find program is no longer preferred for searching for files by name in the entire filesystem. Instead, the locate programs, which use a database of indexed files (obtained through find), are more efficient.

A single white space is needed to divide syntax elements when writing a find command. In it’s simplest use the find command searches for files in the current directory and its subdirectories:

* As always, the dot indicates the current directory.

Search all directories:

find / -name “myfile” -type f -print

This searches every file on the computer for a file with the name myfile. It is generally not a good idea to look for data files this way.

Execute an action

find /var/ftp/mp3 -name “*.mp3? -type f -exec chmod 644 {} \;

This command changes the permissions of all files with a name ending in .mp3 in the directory /var/ftp/mp3.

The action is carried out by specifying the option -exec chmod 644 {} \;

The semicolon (backslashed to avoid the shell interpreting it as a command separator) indicates the end of the command.

EXAMPLES

find /tmp -name core -type f -print | xargs /bin/rm -f

Find files named core in or below the directory /tmp and delete them. Note that this will work incorrectly if there are any filenames containing newlines, single or double quotes, or spaces.

find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f

Find files named core in or below the directory /tmp and delete them, processing file?names in such a way that file or directory names containing single or double quotes, spaces or newlines are correctly handled. The -name test comes before the -type test in order to avoid having to call stat(2) on every file.

find . -type f -exec file ’{}’ \;

Runs ‘file’ on every file in or below the current directory. Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation. The semicolon is similarly protected by the use of a backslash, though’;’ could have been used in that case also.

find $HOME -mtime 0

Search for files in your home directory which have been modified in the last twenty-four hours. This command works this way because the time since each file was last modified is divided by 24 hours and any remainder is discarded. That means that to match -mtime 0, a file will have to have a modification in the past which is less than 24 hours ago.

find . -perm 664

Search for files which have read and write permission for their owner, and group, but which other users can read but not write to. Files which meet these criteria but have other permissions bits set (for example if someone can execute the file) will not be matched.

find . -perm /222

Search for files which are writable by somebody (their owner, or their group, or anybody else).

find . -perm /220

find . -perm /u+w,g+w

find . -perm /u=w,g=w

All three of these commands do the same thing, but the first one uses the octal repre?sentation of the file mode, and the other two use the symbolic form. These commands all search for files which are writable by either their owner or their group. The files don’t have to be writable by both the owner and group to be matched; either will do.

find . -perm -220

find . -perm -g+w,u+w

Both these commands do the same thing; search for files which are writable by both their owner and their group.

find . -perm -444 -perm /222 ! -perm /111

find . -perm -a+r -perm /a+w ! -perm /a+x

These two commands both search for files that are readable for everybody (-perm -444 or -perm -a+r), have at least on write bit set (-perm /222 or -perm /a+w) but are not executable for anybody (! -perm /111 and ! -perm /a+x respectively).

Now, suppose you want to see what hidden files in your home directory changed in the last 5 days:

$ find ~ -mtime -5 -name \.\*

If you know something has changed much more recently than that, say in the last 14 minutes, and want to know what it was there’s the mmin argument:

$ find ~ -mmin 14 -name \.\*

Be aware that doing a ‘ls’ will affect the access time-stamps of the files shown by that action. If you do an ls to see what’s in a directory and try the above to see what files were accessed in the last 14 minutes all files will be listed by find.

SBDavid

Administering RPM based distro

Description

rpm is a powerful Package Manager, which can be used to build, install, query, verify, update, and erase individual software packages. A package consists of an archive of files and meta-data used to install and erase the archive files.

RPM Commands:

  • To install a RPM package.
  1. rpm -ivh elinks.rpm
  • To uninstall a RPM package.
  1. rpm -e elinks.rpm
  • To upgrade a RPM package. RPM automatically uninstall the old version of the foo package and Install the new package.
  1. rpm -Uvh elinks.rpm
  • To query all installed packages.
  1. rpm -qa
  • To query a RPM package.
  1. rpm -q elinks
  • To display package information.
  1. rpm -qi elinks
  • To list files in installed package.
  1. rpm -ql elinks
  • To find out which package owns a file?
  1. rpm -qf /usr/bin/elinks
  • How to find out the list files in RPM file.
  1. rpm -qpl elinks.rpm
  • To verify an installed package.
  1. rpm –verify elinks

Note:

–replacefiles

Install the packages even if they replace files from other, already installed, packages.

–replacepkgs

Install the packages even if some of them are already installed on this system.

–test

Do not install the package, simply check for and report potential conflicts.

Binary RPMs and Source RPMs

There are two main types of RPM packages: binary (or applications) and source. A binary RPM has been compiled for a particular architecture.

A source RPM (SRPM) package typically contains a gzipped tar archive with the source files, and an RPM spec file.

To compile and install a source RPM package on redhat system, you can do the following:

Type:

  1. rpm -ihv elinks.src.rpm
  2.  
  3. rpm -ihv elinks.src.rpm
  4.  
  5. cd  /usr/src/redhat/SPECS
  6.  
  7. rpm -bb elinks.spec

As root, install the binary RPM. It will be located in the directory- /usr/src/redhat/RPMS/i386.

* elinks - lynx-like alternative character mode WWW browser.

Working behind the scenes of the package manager is the RPM database, stored in /var/lib/rpm. It consists of a single database (Packages) containing all of the meta information of the installed rpms and multiple databases used for indexing purposes.

SBDavid

MX Record

More about MX Record

  • An MX record or Mail exchanger record is a type of resource record in the Domain Name System (DNS) specifying how Internet e-mail should be routed using the Simple Mail Transfer Protocol (SMTP).
  • Each MX record contains a priority and a host name, so that the collection of MX records for a given domain name point to the servers that should receive e-mail for that domain, and their priority relative to each other.
  • CNAME aliases are prohibited in an MX record data,
  • The host name contained in an MX record must have an address, i.e. an A or AAAA DNS record.
  • Some mailservers will send mail to domains with IP-based MX records, many (most notably Exim) will refuse to do so.
  • The sending mail transfer agent makes a DNS query requesting the MX records.
  • The sending agent then attempts to establish an SMTP connection to one of these servers, starting with the one with the smallest preference number.
  • If there is more than one entry with the same preference number, all of those must be tried before moving on to lower-priority entries.
  • One technique used to distribute the load of incoming mail over an array of servers is to return the same preference number for each server in the set.
  • The MX mechanism does not grant the ability to provide mail service on alternative ports, nor does it provide the ability to distribute mail delivery across a set of equal-priority mail servers .
  • The MX mechanism provides the ability to run multiple mail servers for a single domain, and allows the specification of an order in which they should be tried.
SBDavid

cPanel and WHM Log Files.

The most important information that we  will probably get are from the log files.  If you are new to Cpanel/WHM you would like to know where the log files are located.

In Short /var/log is the place where you can find out all Linux related log files,  but for applications such as Cpanel/WHM  the log file locations are different. 

 

 Log Files 

  • access_log — A file containing a record of IP addresses of visitors that have accessed sites hosted by your server. This file can be found at /usr/local/apache/logs/access_log.
  • cpdavd_error_log — A file that contains a record of errors that were encountered by cpdavd. This file can be found at /usr/local/cpanel/logs/cpdavd_error_log.
  • cphulkd_errors_log — A file that contains a record of errors encountered by the cphulkd. This file can be found at /usr/local/cpanel/logs/cphulkd_errors.log.
  • error_log — A file that contains a record of errors encountered by the Apache web server. This file can be found at /usr/local/apache/logs/error_log.
  • license_log — A file that contains a record of errors that were encountered when cPanel checked its license. This can be found at /usr/local/cpanel/logs/license_log.
  • login_log — A file that contains a record of failed login attempts. This file can be found at/usr/local/cpanel/logs/login_log.
  • stats_log — A file that contains a record of the activities of cpanellogd, the daemon that compiles your server’s web statistics. This file can be found at /usr/local/cpanel/logs/stats_log.
  • tailwatchd_log — A file that contains a record of errors encountered by tailwatchd, the daemon that monitors your server’s logs. This can be found at  /usr/local/cpanel/logs/tailwatchd_log.

 

« Prev