Search Articles

Showing posts with label Linux Admin. Show all posts
Showing posts with label Linux Admin. Show all posts

VI editor shows the error Terminal too wide within Solaris


Terminal too wide


You may receive the following error when using VI editor within Solaris. I got this error when I was adding tns entry in tnsnames.ora file.



$ vi tnsnames.ora

Terminal too wide




Here, Vi will not allow to edit files. For editing you must increase the number of columns as shown below.


To resolve this increase the number of columns using below command:

stty columns 120


Read more ...

How to Change the Default SSH Port When Selinux is Enable on Linux

In this How-To guide we are going to explain you though changing the default SSH port on a Linux system.

SSH - The Secure Shell Protocol by default uses port 22. You can change this port number for security purpose. If you use Oracle Linux 7, Centos 7 or Red Hat Linux 7 versions, you can change port number with below operations.

Change the default SSH port

Accepting this value does not make your system insecure, nor will changing the port provide a
significant variance in security. However, changing the default SSH port will stop attacker from making unauthorized access or from many automated attacks and a bit harder to guess on which port SSH is accessible from.

 If selinux is enabled, you have to add new port number to selinux configuration because of the fact that selinux allows only 22 port number for ssh connections.


How to Change SSH Port When Selinux is Enable in Linux



STEP1 : As root user, edit the sshd configuration file using default VI editor.
 # vi /etc/ssh/sshd_config

Port 2290

Save and Exit


STEP 2: Edit the line which states 'Port 22'. 
But before doing so, you must choose an appropriate port and also make sure that it not currently used by any other application on the system.

# What ports, IPs and protocols we listen for

Port 2290

Note: The Internet Assigned Numbers Authority (IANA) is responsible for the global coordination of the DNS Root, IP addressing, and other Internet protocol resources. It is good practice to follow their port assignment guidelines. Having said that, port numbers are divided into three ranges: Well Known Ports, Registered Ports, and Dynamic and/or Private Ports. The Well Known Ports are those from 0 through 1023 and SHOULD NOT be used. Registered Ports are those from 1024 through 49151 should also be avoided too. Dynamic and/or Private Ports are those from 49152 through 65535 and can be used. Though nothing is stopping you from using reserved port numbers, our suggestion may help avoid technical issues with port allocation in the future.


STEP 3 : Change Selinux Configuration

To change:
 # semanage port -a -t ssh_port_t -p tcp 2290


To list using grep:
# semanage port -l | grep ssh


STEP 4: Restart SSHD Service to Activate New Confiuration
 # systemctl restart sshd.service

Switch over to the new port by restarting SSH.

#/etc/init.d/ssh restart


STEP 5: Verify SSH is listening on the new port by connecting to it.
Now connect using new port no 2290.
ssh username@hostname.com -p 2290

Read more ...

[A-Z] VI Editor Commands for Editing Files in Linux

For operating systems like Solaris and Linux, you must know some of the basic vi editor commands for the smooth and frequent editing of files. These commands are frequently used in searching patterns within a file, moving arrows up, down, left and right, deleting characters/lines, inserting text etc.

vi editor commands in Linux


vi Editor Commands




Editing and Saving Files


        To create a new file: vi filename
        To exit vi and save changes: [esc][colon] ZZ or wq like Press esc then :wq
        To exit vi without saving changes: :q!
        To saves the current file without quitting: :w
        To enter vi command mode: [esc]
        To enter vi insert mode: Press i



Moving Cursor Within a file


h       move left (backspace)

j       move down

k       move up

l       move right (spacebar)

[return]   move to the beginning of the next line

$       last column on the current line

0       move cursor to the first column on the
current line

^       move cursor to first nonblank column on the
current line

w       move to the beginning of the next word or
punctuation mark

W       move past the next space

b       move to the beginning of the previous word
or punctuation mark

B       move to the beginning of the previous word,
ignores punctuation

        e       end of next word or punctuation mark

        E       end of next word, ignoring punctuation

        H       move cursor to the top of the screen

        M       move cursor to the middle of the screen

        L       move cursor to the bottom of the screen



 Finding Patterns in a File

?       finds a word going backwards

/       finds a word going forwards

        f       finds a character on the line under the
cursor going forward

        F       finds a character on the line under the
cursor going backwards

        t       find a character on the current line going
forward and stop one character before it

T       find a character on the current line going
backward and stop one character before it

; repeat last f, F, t, T



Screen Movement

       G        move to the last line in the file

       xG       move to line x

       z+       move current line to top of screen

       z        move current line to the middle of screen

       z-       move current line to the bottom of screen

       ^F       move forward one screen

       ^B       move backward one line

       ^D       move forward one half screen

       ^U       move backward one half screen

       ^R       redraw screen
( does not work with VT100 type terminals )

       ^L       redraw screen
( does not work with Televideo terminals )

:# move to line #

:$ move to last line of file



Inserting character in a File

       r        replace character under cursor with next
character typed

       R        keep replacing character until [esc] is hit

       i        insert before cursor

       a        append after cursor

       A        append at end of line

       O        open line above cursor and enter append mode



Deleting words and characters within a file

x       delete character under cursor

dd      delete line under cursor

        dw      delete word under cursor

        db      delete word before cursor



Useful Miscellaneous Commands

. repeat last command

u undoes last command issued

U undoes all commands on one line

xp deletes first character and inserts after
second (swap)

J join current line with the next line

^G display current line number

% if at one parenthesis, will jump to its mate

mx mark current line with character x

'x find line marked with character x

NOTE: Marks are internal and not written to the file.

        yy      (yank)'copies' line which may then be put by
the p(put) command. Precede with a count for
multiple lines.



Put Command
        brings back previous deletion or yank of lines,
words, or characters

        P       bring back before cursor

        p       bring back after cursor



Reading Files
copies (reads) filename after cursor in file
currently editing

:r filename



Shell Escape
executes 'cmd' as a shell command.

:!'cmd'

Read more ...

Top 10 Commands to Check CPU Information on Linux

CPU info includes detailed information about the processor, like it's architecture, vendor name, model, number of cores, speed of each core etc. In Linux, there are many command line or GUI-based tools that can be used to show detailed information about your CPU hardware, however we are exploring some of the best and useful commands using which you can get much more detailed information about Linux CPU.

Get CPU info using /proc/cpuinfo on Linux

Linux /proc/cpuinfo file contains details about individual cpu cores. Proc (/proc) file system provides information about CPU and their speed which is a pseudo-filesystem. It is used as an interface to kernel data structures. It is commonly mounted at /proc. You can use command like more, less or grep to see the contents of this file.

Commands to Get CPU Details on Linux


$ less /proc/cpuinfo
siblings        : 16
core id         : 0
cpu cores       : 8
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 sse4_2 x2apic popcnt aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips        : 5199.62
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:
processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
................ etc

You can also get details using more and cat command like:
$ more /proc/cpuinfo
$ cat /proc/cpuinfo


To display number of processors in the system
Every processor or core is listed separately and the various details about speed, cache size and model name are included in the description. To count the number of processing units use grep command with wc.
$cat /proc/cpuinfo | grep processor | wc -l
32
$ grep processor /proc/cpuinfo 
processor       : 0
processor       : 1
processor       : 2
processor       : 3
processor       : 4
processor       : 5
processor       : 6
processor       : 7
processor       : 8
........... ...........
processor       : 29
processor       : 30
processor       : 31 

Note: The number of processors shown by /proc/cpuinfo might be different from the actual number of cores on the processor. For example a processor with 2 cores and hyperthreading would be reported as a processor with 4 cores.


To get the actual number of cores, check the core id for unique values
$ cat /proc/cpuinfo | grep 'core id'
$ cat /proc/cpuinfo | grep 'core id'| wc -l
32


lscpu
lscpu is a small and quick command that does not need any options. It would simply print the cpu hardware details in a human readable format.
$ lscpu


To Find CPU vendor 
If you’re interested in just knowing the CPU vendor, go with cat /proc/cpuinfo along with with the grep command.
$ cat /proc/cpuinfo | grep vendor | uniq
vendor_id       : GenuineIntel


To Find Model Name
$ cat /proc/cpuinfo | grep 'model name' | uniq
model name      : Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz


Hardinfo 
Hardinfo is a gtk based gui utility that generates reports about various hardware components including memory, storage, PCI devices, storage, USB devices etc plus information on the OS, kernel, and networking. But it can also run from the command line only if there is no gui display available.

To install hardinfo
If hardinfo is not installed on your Linux box, you can do so with the following command on your Ubuntu system.
$ sudo apt-get install hardinfo
Let's Look into this command
$ hardinfo | less
It would produce a large report about many hardware parts, by reading files from the /proc directory. The cpu information is towards the beginning of the report. The report can also be written to a text file. Hardinfo also performs a few benchmark tests taking a few minutes before the report is displayed.


To find the number of processing units available
 The nproc command just prints out the number of processing units available. Note that the number of processing units might not always be the same as number of cores.
$ nproc
4


To Display name of the Operating System.
$ uname -a
Linux 2.6.39-400.215.10.el5uek #1 SMP Tue Sep 10 22:51:46 PDT 2014 x86_64 x86_64 x86_64 GNU/Linux


Inxi
 One of my all time favorite command line tools and I have it running on all my Linux systems. This is an excellent script that provides information in an easy to understand format.

To install Inix on Ubuntu
$ sudo apt-get install inxi

To install Inix on CentOS/Fedora
$ sudo yum install inxi

Print out cpu/processor related information 
$ inxi -C


dmidecode
The dmidecode command displays some information about the cpu, which includes the socket type, vendor name and various flags. Following command with type id 4 will get the information about CPU of the system.
# dmidecode -t 4
# dmidecode 2.9
$sudo demidecode -t processor
$ sudo dmidecode -t 4
Get BIOS information using dmidecode
# dmidecode -t bios
# dmidecode 2.9
View Manufacturer, Model and Serial number of the equipment using dmidecode
# dmidecode -t system
# dmidecode 2.9


cpuid
The cpuid command fetches CPUID information about Intel and AMD x86 processors.

This program can be installed with apt on ubuntu
$ sudo apt-get install cpuid

To install cpuid on Fedora and CentOS distributions.
$ sudo yum install cpuid

And here is sample output
$ cpuid

Run the command with less to get a readable output.
$ cpuid | less


You can also do R&D with grep command to find more cpu info in Linux/Unix. From the readers, your comment is valuable to us. Please share if you have more valuable commands to get more detailed output.


Other similar sources:

nixCraft: Number of CPUs and Their Speed
redhax: /proc/cpuinfo.html
linuxquestions.org
Read more ...

35 Practical Find Command Examples in Linux

Find Command is one of the powerful Unix / Linux utility used for searching the files in a directory hierarchy from the command line. It can be used to find files based on various search criteria like permissions, user ownership, modification date/time, size etc.
In this post we shall learn to use the find command along with various options that it supports.


Find Command Best Examples


The basic syntax syntax of find command is:
find [pathnames] [conditions]


You have several options for matching criteria:

-atime n : File was accessed n days ago
-mtime n : File was modified n days ago
-size n : File is n in size (a block is 512 bytes)
-type c : Specifies file type: f=text file, d=directory
-fstype : Specifies file system type example nfs
-name : Name of the filen you want to search
-user : Specifies file's owner
-group : Specifies file's group owner
-perm p : File's access mode

Some examples based on the above criteria:

-mtime +7 : Matches files modified more than seven days ago.
-atime -2 : Matches files accessed less than two days ago
-size +100 : Matches files larger than 100 blocks (50KB)
-mmin -60 : find all the files which are modified in last 1 hour
-cmin -60 : find all the files which are changed in last 1 hour


Most Frequently Used Find Command Examples in Linux



Find Files Under Home Directory
Find all the files under /home directory with name foo.txt.
# find /home -name foo.txt
/home/foo.txt


Find Files Using Name in Current Directory
Find all the files whose name is foo.txt in a current working directory.
# find . -name foo.txt
./foo.txt


Find files starting from the root directory
# find / -name passwd
This command will find passwd file under all sub-directories starting from root directory.


Find Files Using Name and Ignoring Case
Find all the files whose name is ora.txt and contains both capital and small letters in /home directory.
# find /home -iname Foo.txt
./Foo.txt
./Foo.txt


Find and remove single File
To find a single file called ora.txt and remove it.
# find . -type f -name "ora.txt" -exec rm -f {} \;


Find and remove Multiple File with same extension
To find and delete all files of a specific extension such as .txt, .gz use.
# find . -type f -name "*.txt" -exec rm -f {} \; 


Find Directories Using Name
Find all directories whose name is foo in / directory.
# find / -type d -name foo
/foo


Find hidden files
Hidden files on linux begin with a period (.).  list all hidden files. This command will list all hidden files in the specific directory like temp etc.
# find /tmp -type f -name ".*"
# find ~ -type f -name ".*"
Note: Use proper directory path.


Finding top 10 largest files in Linux
The following command will display the top 10 biggest file in the current directory and its subdirectory. This may take a while to execute depending on the total number of files and size of the files.
# find . -type f -exec ls -s {} \; | sort -n -r | head -10 


Finding the Top 10 Small Files
The following command will display the top 10 smaller file in the current directory and its subdirectory. but the only difference the sort is ascending order.
# find . -type f -exec ls -s {} \; | sort -n -r | head -5 

In the above command, you will see ZERO byte files also ( empty files ). So,  you can use the following command to list the smaller files other than the ZERO byte.
# find . -not -empty -type f -exec ls -s {} \; | sort -n  | head -5 


Finding Files based on Modification and accessed time


Find files modified 20 days back
To find all the files which are modified 20 days back.
# find / -mtime 20


Find files accessed in last 20 days
Find all files that were accessed in the last 20 days.
# find / -atime 20


Find files modified in a range of days
Find all files that were modified between 50 to 100 days ago.
# find / -mtime +50 –mtime -100 


Find Changed Files in Last 1 Hour
To find all the files which are changed in last 1 hour.
# find / -cmin -60


Find Modified Files in Last 1 Hour
To find all the files which are modified in last 1 hour.
# find / -mmin -60 


Find Accessed Files in Last 1 Hour
To find all the files which are accessed in last 1 hour.
# find / -amin -60 


Finding Files based on Size
Using the -size option you can find files by size.


Find files bigger than 100M
# find ~ -size +100M 


Find files smaller than 100M
# find ~ -size -100M 


Find 50MB Files
To find all files matches the exact given size i.e, 50M
# find / -size 50M 


Find Size between 50MB – 100MB
To find all the files which are greater than 50MB and less than 100MB.
# find / -size +50M -size -100M 


Find and Delete 100MB Files
To find all 100MB files and delete them using one single command.
# find / -size +100M -exec rm -rf {} \; 


Find Files and Directories based on type using option -type


Find only the normal files
# find . -type f 


Find all directories
# find . -type d 


Find only the socket files.
# find . -type s 


Find all the hidden files
# find . -type f -name ".*" 


Find all the hidden directories
# find -type d -name ".*" 


Find Specific Files and Delete
Find all .mp3 files with more than 10MB and delete them using one single command.
# find / -type f -name *.mp3 -size +10M -exec rm {} \; 


Find all Empty Directories
To file all empty directories under specific path.
# find /tmp -type d -empty 


Finding Files based on Permissions

Find Files having 777 Permissions
Find all the files whose permissions are 777
# find . -type f -perm 0777 -print 


Find Files Without 777 Permissions
Find all the files without permission 777.
# find / -type f ! -perm 777 


Find SGID Files with 644 Permissions
Find all the SGID bit files whose permissions set to 644.
# find / -perm 2644 


Find Sticky Bit Files with 551 Permissions
Find all the Sticky Bit set files whose permission are 551.
# find / -perm 1551 


Find SUID Files
Find all SUID set files.
# find / -perm /u=s 


Find SGID Files
Find all SGID set files.
# find / -perm /g+s 


Find Read Only Files
Find all Read Only files.
# find / -perm /u=r 


Find Executable Files
Find all Executable files.
# find / -perm /a=x 


Find Files with 777 Permissions and Chmod to 644
Find all 777 permission files and use chmod command to set permissions to 644.
# find / -type f -perm 0777 -print -exec chmod 644 {} \; 


Find Directories with 777 Permissions and Chmod to 755
Find all 777 permission directories and use chmod command to set permissions to 755.
# find / -type d -perm 777 -print -exec chmod 755 {} \;
Read more ...

Top 20 Practical Examples of RPM Commands in Linux

RPM is a default open source package management utility for installing, updating, uninstalling, querying and verifying software packages on Linux based operating systems.  RPM stands for Red Hat Package Manager which keeps the information of all the installed packages under /var/lib/rpm database.  It is mostly used in  RHEL, CentOS and Fedora.

Best Practical Examples of RPM Commands in Linux

RPM has five basic modes of operation which includes:


Install: It is used to install RPM package.
Uninstall:  It is used to remove or uninstall RPM package.
Upgrade: It is used to update the existing RPM package.
Verify: It is used to query about different RPM packages.
Query: It is used for the verification of any RPM package.


 Each software package consists of an archive of files along with information about the package like its name, version, and a description,

Sources From Where you can find and download RPM packages
Below are the list of sites where you can find and download all RPM packages.

http://www.rpmfind.net/
www.redhat.com/
http://freshrpms.net/ 
http://rpm.pbone.net/

1. To install a RPM package, use the following command:

# rpm -ivh foo-1.0-2.i386.rpm

Preparing...           ############################## [100%]

   1:foo               ############################## [100%]

Structure of the package includes the following:

  • File of names like foo-1.0-2.i386.rpm
  • Package name - foo
  • Version - 1.0 
  • Release - 2  
  • Architecture - i386

2. To remove an installed RPM package, use RPM with -e option
After uninstallation, you can query using rpm -qa to verify the uninstallation
# rpm -ev foo
 
Notice that we used the package name “foo”, not the name of the original package file “foo-
1.0-2.i386.rpm”.


3. To query a particular RPM package, use this command with -q option
This command will print the package name, version, and release number of the installed package foo. Use this command to verify that a package is or is not installed on your system.
# rpm -q foo
foo-2.3-8


To Query all RPM packages using rpm -qa
# rpm -qa
This command will list all the installed packages on your system. To filter particular package you can combine this with grep command.
# rpm -qa | grep BitTorrent


4. To upgrade a RPM package, use with -Uvh option
With this command, RPM automatically uninstalls the old version of installed package for example  foo and installs the new version. Always use rpm -Uvh to install packages, since it works fine even when there are no previous versions of the package installed.
# rpm -Uvh foo-1.0-2.i386.rpm
foo ##################################################


5. To display package information, use the command
This command displays package information; includes name, version and description of the
installed program. Use this command to get information about the installed package.
# rpm -qi foo
Name : foo Relocations: none
Version : 2.3 Vendor: OpenNA.com, Inc.
Release : 8 Build Date: Thu 24 Aug 2000 11:16:53 AM EDT
Install date: Mon 12 Feb 2001 01:17:24 AM EST Build Host: openna.com
Group : Applications/Archiving Source RPM: foo-2.3-8.src.rpm
Size : 271467 License: distributable
Packager : OpenNA.com, Inc. <http://www.openna.com/>
Summary : Here will appears summary of the package.
Description : Here will appears the description of the package.


6. To display package information before installing the program
This command displays package information before installing on your system which includes name, version, and description of the program. Use this command to get information about a package before you install it on your system. For example, the following option -qip (query info package) will print the information of a package.
# rpm -qpi foo-2.3-8.i386.rpm
Name : foo Relocations: none
Version : 2.3 Vendor: OpenNA.com, Inc.
Release : 8 Build Date: Thu 24 Aug 2000 11:16:53 AM EDT
Install date: Mon 12 Feb 2001 01:17:24 AM EST Build Host: openna.com
Group : Applications/Archiving Source RPM: foo-2.3-8.src.rpm
Size : 271467 License: distributable
Packager : OpenNA.com, Inc. <http://www.openna.com/>
Summary : Here will appears summary of the package.
Description : Here will appears the description of the package.


7. To check dependencies of RPM Package before Installation
To view the list of packages on which this package depends you can use rpm -qpR command. This command will display the list of all packages on which installing package depends before installing or upgrading a package. This is the best way to do a dependency check before installing or upgrading a package.
# rpm -qpR <package_name>
# rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm

/usr/bin/python2.4
python >= 2.3
python(abi) = 2.4
python-crypto >= 2.0
python-psyco
python-twisted >= 2.0
python-zopeinterface
rpmlib(CompressedFileNames) = 2.6
RPM command and options
-q : Query a package
-p : List capabilities this package provides.
-R: List capabilities on which this package depends.


8. To list files in a installed RPM package, use the command
This command will list all files in a installed RPM package. It works only when the package is
already installed on your system.
# rpm -ql foo
/usr/bin/foo
/usr/bin/foo1
/usr/sbin/foo2


9.  To Query documentation of Installed RPM Package
To get the list of available documentation of an installed package, use the following command with option -qdf (query document file). This command will display the location of all manual pages related to package. Here, for example vmstat.
# rpm -qdf /usr/bin/vmstat

/usr/share/doc/procps-3.2.8/BUGS
/usr/share/doc/procps-3.2.8/COPYING
/usr/share/doc/procps-3.2.8/COPYING.LIB
/usr/share/doc/procps-3.2.8/FAQ
/usr/share/doc/procps-3.2.8/NEWS
/usr/share/doc/procps-3.2.8/TODO


10. To list files in package that is not already installed, use the command
This command will list all files in a RPM package that is not already installed on your system. It is useful when you want to know which components are included in the package before installing it.
# rpm -qpl foo
/usr/lib/foo
/usr/bin/foo1
/usr/sbin/foo2


11. To know which files is part of which package, use the command
# rpm -qf /etc/passwd
setup-2.3.4-1
This command will show you from which RPM package the file comes from. It works only when the package is already installed on your system and it is very useful when you see some files into Linux that you do not and want to get detailed information about it.


12. To check a RPM signature package, use the command
# rpm --checksig foo

  • This command checks the PGP signature of specified package to ensure its integrity and origin.
  • Always use this command first before installing new RPM package on your system.
  • GnuPG or PGPsoftware must be already installed on your system before you can use this command.



13. To examine only the md5sum of the package, use the command
# rpm --checksig --nogpg foo


14. To Rebuild corrupted RPM database
Sometimes RPM database gets corrupted, in that situation you need to rebuild corrupted RPM database. In order to recover from a corrupted RPM database you can use the following command:
First of all remove /var/lib/rpm/__db* files to avoid stale locks and then rebuild rpm using below command:
# cd /var/lib
# rm __db*

Rebuild RPM database:
# rpm --rebuilddb
# rpmdb_verify Packages


15. How to List Recently Installed RPM Packages
Use the following rpm command with -qa (query all) option, this will list all the recently installed rpm packages on your system.
# rpm -qa --last
Some Facts about RPM (RedHat Package Manager) RPM is free and released under GPL (General Public License). RPM keeps the information of all the installed packages under /var/lib/rpm database. RPM is the only way to install packages under Linux systems, if you’ve installed packages using source code, then rpm won’t manage it. RPM deals with .rpm files, which contains the actual information about the packages such as: what it is, from where it comes, dependencies info, version info etc.


16. How to List all Imported RPM GPG keys
To print all the imported GPG keys in your system, use the following command.
# rpm -qa gpg-pubkey 
gpg-pubkey-58f96f56-467e919a
gpg-pubkey-6b8d79e6-3f49413d
gpg-pubkey-849c449f-4cb9ff31
gpg-pubkey-5680b795-4bd22941
 gpg-pubkey-7fac5991-461576f7
 gpg-pubkey-0f2672c8-4cd925ee
gpg-pubkey-c106b9de-4e0fd3a3


17. How to Import an RPM GPG key
To verify RHEL/CentOS/Fedora packages, you must import the GPG key. To do so, execute the following command. It will import CentOS 6 GPG key. 
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

Additional resources to learn more about rpm.
rpm --help : This command displays a quick reference of RPM parameters.
man rpm : The RPM man page gives more detail about RPM parameters than the rpm --help command.

Useful Websites
The RPM website — http://www.rpm.org/

Read more ...

Linux Crontab: Cron and Crontab usage and Examples


Crontab-Examples


Linux Crontab Format - Cron Job Sceduling, usage with Examples


The content of the file can be divided in to 6 fields(first 5 for specifying time and last one for executing scripts/app etc). The first five fields are separated by either a space or a tab and represent the following units, respectively:
* minutes (0-59)

* hour (0-23)

* day of the month (1-31)

* month of the year (1-12)

* day of the week (0-6, 0=Sunday)

An example of crontab format with commented fields is as follows:

# Minute   Hour    Day of Month      Month           Day of Week        Command   
# (0-59)  (0-23)     (1-31)      (1-12 or Jan-Dec)  (0-6 or Sun-Sat) 
           

Allowed special character for job scheduling(*, -, /, ?, #)

Asterik(*) – Match all values in the field or any possible value
Hyphen(-) – To define range.
Slash (/) – 1st field /10 meaning every ten minute or increment of range.
Comma (,) – To separate items.
Hash  (#) - To comment job, or to make a job inactive.



1. To View/List Crontab Entries
To List or view crontab job entries you can use crontab command with -l option, here you will see all the scheduled jobs.
# crontab -l

00 10 * * * /bin/ls >/ls.txt

2. To Edit Crontab Entries
To edit crontab entry, use -e option with crontab as shown below. After proper entry press escap :wq which saves the file and will make necessary changes after editing.
# crontab -e

3.To Remove Crontab Entries
Caution: Crontab with -r parameter will remove complete scheduled jobs without your confirmation from crontab. You can use -i option which confirm's you before removing entries.
# crontab -r

4. Ask Confirmation Before Deleting Crontab
crontab with -i option will prompt you confirmation from user before deleting user’s crontab.
# crontab -i -r

crontab: really delete root's crontab?

5. To Create Crontab for a User
As a root user you can create crontab entries for a particular user using the following command.
#crontab -e -u username

-e is for editing and -u for specifying user name when you are scheduling crontabs for other users. If users want to schedule their own he can just give (crontab -e). After entering the values save and exit the file. A file will be created in crontab file location as /var/spool/cron/orahow with the above content.

6. To View User’s Crontabs entries
To view crontab entries of other Linux users, login as root and use -u {username} -l as shown below.
[root@orahow]# crontab -u santosh -l
@monthly /home/santosh/monthly-backup
00 09-18 * * * /home/santosh/check-db-status 
7. To Check Cron Process
To find out what are the cron jobs which are running at any instant on a Solaris server, you can use ps command which list all the cron jobs which are running on the server. To Check if the 'cron' daemon is running.
ps -ef | grep cron

There should be a process: /usr/sbin/cron that started at the same time as the system booted (check with who -b).

You can 'bounce' the cron daemon, if you want, with:
/etc/init.d/cron stop
/etc/init.d/cron start

 Most frequently used Crontab Examples in Linux/Unix.


1. Schedule a cron to execute at 5 am daily. 
To schedule a job at 5 am daily, you can edit entries as shown below.
0 5 * * * /var/test/script.sh > /temp/script.out 

2. Schedule a cron to execute on every Sunday at 6 PM.
This type of cron are useful for doing weekly tasks, like backup, log rotation etc.

0 18 * * sun  /var/test/script.sh > /temp/script.out

3. Schedule a cron to execute on every 15 minutes.
If you want to run your script on 15 minutes interval, can configure entries like below. These type of crons are usefull for monitoring.

*/15 * * * * /var/test/script.sh > /temp/script.out

*/15: means to on each 15 minutes.

 4. Schedule a cron to execute on every six hours.
If you want to run script on 6 hours interval. It can be configure like below.

0 */6 * * * /var/test/script.sh > /temp/script.out 

5. To Schedule Job on every weekday(Mon to Fri) during the working hours 10 a.m – 6 p.m.

00 10-18 * * 1-5 /var/test/script.sh > /temp/script.out 

00 – 0th Minute
10-18 : At 10 am,11 am, 12 am, 1 pm, 2 pm, 3 pm, 4 pm, 5 pm, 6 pm
* : Every day
* : Every month
1-5 : Mon, Tue, Wed, Thu and Fri

6. To execute script on every 10th of each month at 11:45pm
Script located in /var/test/script.sh executed at given time and save output to the /temp/script.out.
45 23 10 * * /var/test/script.sh > /temp/script.out 

here * in month field and week field indicates any month and any week execute this script

7. To schedule job on every minute of every hour of every day of every month.
This line executes the "ping" command every minute of every hour of every day of every month. The standard output is redirected to dev null so we will get no e-mail but will allow the standard error to be sent as a e-mail. If you want no e-mail ever change the command line to "/sbin/ping -c 1 192.168.0.1 > /dev/null 2>&1".

*       *       *       *       *       /sbin/ping -c 1 192.168.0.1 > /dev/null 

You can also use some of the Special strings for job scheduling:

string         meaning
------         -------

@reboot        Run once, at startup.
----------------------------------------------
@yearly        Run once a year, "0 0 1 1 *".
----------------------------------------------
@annually      (same as @yearly)
----------------------------------------------
@monthly       Run once a month, "0 0 1 * *".
----------------------------------------------
@weekly        Run once a week, "0 0 * * 0".
----------------------------------------------
@daily         Run once a day, "0 0 * * *".
----------------------------------------------
@midnight      (same as @daily)
-----------------------------------------------
@hourly        Run once an hour, "0 * * * *".

 Schedule a job to execute on yearly basis.
@yearly timestamp is similar to “0 0 1 1 *”. This will execute job at 00:00 on Jan 1st for every year.
@yearly /var/test/script.sh 

Schedule a tasks to execute on monthly
@monthly timestamp is similar to “0 0 1 * *”. This will execute job at 00:00 on 1st of every month.
@monthly /var/test/script.sh 

 Schedule a tasks to execute on Weekly.
@weekly timestamp is similar to “0 0 1 * *”. It will execute task on first minute of month. It may usefull to do weekly tasks like cleanup of system etc.
@weekly /var/test/script.sh 

 Schedule a tasks to execute on daily ( @daily ).
@daily timestamp is similar to “0 0 * * *”. It will execute job at 00:00 on every day..
@daily /scripts/script.sh 

 Schedule a tasks to execute on hourly ( @hourly ).
@hourly timestamp is similar to “0 * * * *”. It will execute task on first minute of every hour.
@hourly /var/test/script.sh 

Schedule a tasks to execute on system reboot
@reboot is usefull for those tasks which you want to run on your system startup. It will be same as system startup scripts. It is usefull for starting tasks in background automatically.

@reboot /var/test/script.sh 
System Wide Cron Schedule
you can also use predefine cron directory for job scheduling as shown below.
/etc/cron.d
/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly
So this is all about Linux crontab for cron job scheduling. Here we have explained basics and limited usage examples, if you are planning to deploy any script under crontab we recommend you to cross-verify again from experts or from similar sources.
Read more ...

Install Wine in RHEL/CentOS/Ubuntu 7.0/6.x/5.x and Fedora 21-12

Wine is used To Run Windows Software on Linux. Linux users generally search for some techniques using which they could install Windows .exe files like VLC, on Linux machine. In this article you will show you a step by step process on "how to install latest version of Wine on Red Hat - RHEL and Debian based operating systems like CentOS, Fedora, Ubuntu, Linux Mint and other supported distributions.


Install Wine on RedHat, Ubantu, CentOS, Fedora


Some of the Extra Features Added In this New Release:

  • New version of the Mono engine.
  • A few more functions implemented in MSHTML.
  • Improved support for restoring display mode.
  • Font metrics improvements in DirectWrite.
  • Various types of bug fixes in this new release.

How to install Wine on redhat Linux based operating Systems

Before wine installation we need to install some of the "Development tools" which is required to install the package smoothly. These tools are mostly required to compile and install them using YUM command. If previously installed no need to install again.

#yum groupinstall 'Development Tools'
# yum install libX11-devel freetype-devel zlib-devel libxcb-devel


 Download Wine Packages for Installation from Source using Wget Command

Download the latest version of source file using Wget command under /tmp directory as a normal User, you can also find the latest release from the wine website.

https://www.winehq.org/

$ cd /tmp

$ wget http://citylan.dl.sourceforge.net/project/wine/Source/wine-1.7.32.tar.bz2


Now, extract the downloaded tar file using the following command

$ tar -xvf wine-1.7.32.tar.bz2

To install extracted Wine Packages

Now, it’s time to compile and build Wine installer using the following commands as normal user, if asked for root password provide the same. Note: The installation process might take up-to 10-15 minutes depending upon your internet speed.


On 64-Bit Systems

$ cd wine-1.7.32/

$ ./configure --enable-win64

$ make

# make install


On 32-Bit Systems

# cd wine-1.7.32/

#./configure

# make

# make install

To Install Wine On Ubuntu, Debian and Linux Mint

Under Ubuntu based systems, you can easily install the latest development build of Wine using the official PPA. Open a terminal and run the following commands with sudo privileges.
$ sudo add-apt-repository ppa:ubuntu-wine/ppa

$ sudo apt-get update

$ sudo apt-get install -y wine1.7 winetricks

How to Install and run EXE files in Linux, RHEL, CentOS, Fedora, Ubantu

Navigate to the directory location of your windows application setup file and double click on it. It will automatically start the installation of the application (.exe) file. If it does not work then you can start the installation process from the terminal by typing the following command:

wine your_application_setup_file_name.exe

example:

wine VLC.exe

Read more ...

How to Make a File Write Protected in Linux

In Linux there is an additional file attribute which prevent files and folders from being deleted accidentally. Flag which make a file write/delete protected even from root is called immutable flag. Linux administrator must set this flag for various configuration files on the production servers so that no one could delete/temper with these files.


Prevent file from being deleted


When you want to delete file/folder having immutable flag set, you will encounter with an error:
rm: cannot remove 'file-name': Operation not permitted.

Making file write protected in Linux

To set this flag we use plus (+) sign with chattr command and to unset this flag we use minus (-) sign.


Syntax:

To set this flag on files you can use the following command:
chattr +i filename

To unset or remove the attribute you can use the following command:
 chattr -i filename 


To set this flag on directories only you need to specify the directory name:

 chattr +i directory name 

chattr -i directory name 


How to search files having immutable flag set?
To accomplish this we use lsattr command pipe with the grep command.

lsattr -R | grep +i

Example:

Creating file having name san.txt and setting flag on it.
[oracle@orahow ~]$ vi san.txt

Initially check the file permission:
[oracle@orahow ~]$ ls -l san.txt
-rw-r--r-- 1 oracle dba 19 Nov 18 05:56 san.txt

 [oracle@orahow ~]$ chattr +i san.txt

chattr: Operation not permitted while setting flags on san.txt


To set this flag you need to login as a root user:

[root@orahow oracle]# chattr +i san.txt

[root@orahow oracle]# lsattr san.txt
----i-------- san.txt 


Now try to delete the file having immutable flag set:
[root@orahow oracle]# rm san.txt

rm: remove write-protected regular file `san.txt'? y

rm: cannot remove `san.txt': Operation not permitted

To remove this file you need to unset this flag:

[root@orahow oracle]# chattr -i san.txt

[root@orahow oracle]# lsattr san.txt

------------- san.txt

[root@orahow oracle]# rm san.txt
rm: remove regular file `san.txt'? y
[root@orahow oracle]# cat san.txt
cat: san.txt: No such file or directory

Making a directory write protected in Linux:

[root@orahow oracle]# mkdir san
[root@orahow oracle]# ls -ldr san

drwxr-xr-x 2 root root 4096 Nov 18 07:36 san

[root@orahow oracle]# chattr +i san
Now if you try to remove the directory it will throw a message: operation not permitted. Before deleting this folder you need to unset this flag.

[root@orahow oracle]# rmdir san
rmdir: san: Operation not permitted

[root@orahow oracle]# chattr -i san

[root@orahow oracle]# rmdir san

[root@orahow oracle]# ls -ldr san

ls: san: No such file or directory




Read more ...

CONTACT

Name

Email *

Message *