Subscribe News Feed Subscribe Comments

Changing Date and Time in Linux

Syntex:
1. date -s "DD Mon YYYY hh:mm:ss"

2. date set="DD Mon YYYY hh:mm:ss"

3. date MMDDhhmmYYYY.ss

Example:
1. date -s "28 NOV 2008 13:45:00"

2. date set="28 NOV 2008 13:45:00"

3. date 112813452009

Setting Time in Linux

Syntex:
date +%T -s "hh:mm:ss"

Example:
date +%T -s "10:13:13"

Read rest of the content

Deleting Files/Folders based on OWNERSHIP

1. List the files and directories.

$ ls -lah

total 52K
drwxrwxrwt 11 root root 4.0K Nov 4 03:52 .
drwxr-xr-x 25 root root 4.0K Oct 6 03:54 ..
srwxr-xr-x 1 george george 0 Oct 8 00:47 .dguardianipc
srwxr-xr-x 1 george george 0 Oct 8 00:47 .dguardianurlipc
-rw-r--r-- 1 root root 0 Nov 4 03:52 file1
-rw-r--r-- 1 gopher gopher 0 Nov 4 03:52 file2
-rw-r--r-- 1 gopher gopher 0 Nov 4 03:52 file3
-rw-r--r-- 1 gopher gopher 0 Nov 4 03:52 file4
-rw-r--r-- 1 gopher gopher 0 Nov 4 03:52 file5
-rw-r--r-- 1 root root 0 Nov 4 03:52 file6
-rw-r--r-- 1 root root 0 Nov 4 03:52 file7
drwxrwxrwt 2 root root 4.0K Oct 1 07:55 .font-unix
drwxrwxrwt 2 root root 4.0K Oct 1 07:55 .ICE-unix
drwxr-xr-x 2 root root 4.0K Nov 4 03:43 test1
drwxr-xr-x 2 root root 4.0K Nov 4 03:51 test2
drwxr-xr-x 2 root root 4.0K Nov 4 03:43 test[2-7]
drwxr-xr-x 2 root root 4.0K Nov 4 03:43 test2-7
drwxr-xr-x 2 george george 4.0K Nov 4 03:51 test3
drwxr-xr-x 2 george george 4.0K Nov 4 03:51 test4
drwxr-xr-x 2 george george 4.0K Nov 4 03:51 test5

2. Let's try deleting the files with an owner 'gopher'

List the files with gopher owner.

$ ls -lah | grep gopher

output:
-rw-r--r-- 1 gopher gopher 0 Nov 4 03:52 file2
-rw-r--r-- 1 gopher gopher 0 Nov 4 03:52 file3
-rw-r--r-- 1 gopher gopher 0 Nov 4 03:52 file4
-rw-r--r-- 1 gopher gopher 0 Nov 4 03:52 file5

The output are from file2 to file5, next task is to list the exact filenames using awk.

$ ls -lah | gopher | awk '{print $9}

Output:
file2
file3
file4
file5

Now that the output list only filenames, we can now delete the files.

$ rm -fv `ls -lah | grep gopher | awk '{print $9}'`

Output:
removed `file2'
removed `file3'
removed `file4'
removed `file5'

If its a directory you can issue this pattern:

$ rm -fvR `ls -lah | grep george | awk '{print $9}'`

Output:
removed directory: `test3'
removed directory: `test4'
removed directory: `test5'

Note: be sure to replace the 'grep (owner)' with the specified owner/user.

Read rest of the content

Easy way to extract Logs on a Date/Line Range in LINUX

Example: range of date to be extracted in the /var/log/message. Oct 26-27
our x will be Oct 26, y will be Oct 27

1. Get the first line number which will be our x reference (x - Oct 26).

$ grep -n 'Oct 26' /var/log/messages | head

The initial reference of x = 29933

Sample Output:

29933:Oct 26 00:00:00 postfix nagios: LOG ROTATION: DAILY
29934:Oct 26 00:00:00 postfix nagios: LOG VERSION: 2.0
29935:Oct 26 00:00:00 postfix nagios: CURRENT HOST STATE: localhost;UP;HARD;1;PING OK - Packet loss = 0%
29936:Oct 26 00:00:00 postfix nagios: CURRENT SERVICE STATE: localhost;Current Load;OK;HARD;1;OK
29937:Oct 26 00:00:00 postfix nagios: CURRENT SERVICE STATE: localhost;Current Users;OK;HARD;1
29938:Oct 26 00:00:00 postfix nagios: CURRENT SERVICE STATE: localhost;HTTP;WARNING
29939:Oct 26 00:00:00 postfix nagios: CURRENT SERVICE STATE: localhost;PING;OK;HARD;1;PING OK - Packet loss = 0%
29940:Oct 26 00:00:00 postfix nagios: CURRENT SERVICE STATE: localhost;Root Partition;OK;HARD;1;DISK OK - free space
29941:Oct 26 00:00:00 postfix nagios: CURRENT SERVICE STATE: localhost;SSH;OK;HARD;1;SSH OK
29942:Oct 26 00:00:00 postfix nagios: CURRENT SERVICE STATE: localhost;Swap Usage;OK;HARD;1;


2. Get the last line number which will be our y reference (x - Oct 27).

$ grep -n 'Oct 27' /var/log/messages | tail

The last reference of y = 89712

Sample Output:

89703:Oct 27 23:59:14 postfix snmpd[18448]: -- IF-MIB::ifPhysAddress.1
89704:Oct 27 23:59:16 postfix snmpd[18448]: Connection from UDP: [192.168.0.x]:1055
89705:Oct 27 23:59:26 postfix last message repeated 15 times
89706:Oct 27 23:59:36 postfix snmpd[18448]: Connection from UDP: [192.168.0.131]:4118
89707:Oct 27 23:59:36 postfix snmpd[18448]: Received SNMP packet(s) from UDP: [192.168.0.x]:4118
89708:Oct 27 23:59:36 postfix snmpd[18448]: send response: Failure in sendto
89709:Oct 27 23:59:36 postfix snmpd[18448]: -- SNMPv2-MIB::sysObjectID.0
89710:Oct 27 23:59:36 postfix snmpd[18448]: -- IF-MIB::ifPhysAddress.1
89711:Oct 27 23:59:36 postfix snmpd[18448]: Connection from UDP: [192.168.0.x]:1055
89712:Oct 27 23:59:56 postfix last message repeated 23 times

3. Use the x,y reference to extract the file : x = 29933, y =89712

$ sed -n '29933,89712p' /var/log/messages
> newfilename

Read rest of the content

Google Sitemap Generator Installation in a CentOS Platform

1. Download Google Site Map Generator:

http://code.google.com/p/googlesitemapgenerator/downloads/list

2. Unpack the downloaded file

$ tar –zxvf sitemap_linux-i386-beta1-20090225.tar.gz

3. Run the installation script

$ cd sitemap-install/
$ ./install.sh -t /usr/sbin/apachectl -g apache

Other options:
* -h displays help about these command line options.
* -d directory specifies a non-default installation directory.
* -a Apache-binary-filename specifies the path to the Apache binary file (httpd).
Alternatively, you can specify this value during installation.
* -c Apache-config-filename specifies the Apache root configuration file.
* -g Apache-group specifies the user group name under which Apache is running.
* -t Apache-control-filename specifies the Apache control script (apache ctl).
If you specify this value, the installer lets you choose to automatically
restart Apache at the end of the installation.
If you omit this option, you'll need to restart Apache manually.

Just simply follow the installation, everything is interactive.

4. By default you can access the sitemap generator via port 8181

e.g. http://yourserver:8181/

5. Initialy you will be denied accessing it remotely. Run this in the terminal to enable remote access.

$ /usr/local/google-sitemap-generator/bin/sitemap-daemon remote_admin enable

6. Install SSL requirements.

$ yum install mod_ssl openssl

7. Generate a self-signed certificate

Generate private key
$ openssl genrsa -out ca.key 1024

Generate CSR
$ openssl req -new -key ca.key -out ca.csr

Generate Self Signed Key
$ openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt

Move the files to the correct locations
$ mv ca.crt /etc/pki/tls/certs
$ mv ca.key /etc/pki/tls/private/ca.key
$ mv ca.csr /etc/pki/tls/private/ca.csr

8. Then update the Apache SSL configuration file

$ vi +/SSLCertificateFile /etc/httpd/conf.d/ssl.conf

Comment the existing and add the following:

SSLCertificateFile /etc/pki/tls/certs/ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.key

Restart the apache server

$ /etc/init.d/httpd restart

9. Edit the sitemap generator httpd configuration.

$ vi /usr/local/google-sitemap-generator/conf/httpd.conf

Add the SSL lines, or you can simply paste the code below

Listen 8181
NameVirtualHost *:8181
<VirtualHost *:8181>
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.key
DocumentRoot "/usr/local/google-sitemap-generator/admin-console"
ScriptAlias /cgi-bin/ "/usr/local/google-sitemap-generator/admin-console/cgi-bin/"

<Directory "/usr/local/google-sitemap-generator/admin-console" >
# Allow from all
AllowOverride All
Options ExecCGI
DirectoryIndex index.html
</Directory>
</VirtualHost>


LoadModule google_sitemap_generator_module "/usr/local/google-sitemap-generator/lib/mod_sitemap.so"

10. Restart Apache and that's It.

$ /etc/init.d/httpd restart


Starting and Stopping Google Sitemap Deamon

$ /usr/local/google-sitemap-generator/bin/sitemap-daemon service start
$ /usr/local/google-sitemap-generator/bin/sitemap-daemon service stop
$ /usr/local/google-sitemap-generator/bin/sitemap-daemon service restart

Read rest of the content

MySQL Commands - Adding User, Backup and Restore

Adding new user to access the database

Syntax:
mysqldump -u [username] -p [password] [databasename] > [backupfile.sql]

Examples:
mysql> GRANT all ON mydatabase.* TO myuser@'192.168.17.186' IDENTIFIED BY 'mypassword';
mysql> GRANT all ON mydatabase.* TO myuser@'localhost' IDENTIFIED BY 'mypassword';
mysql> FLUSH PRIVILEGES;


Making Backup of the Database

Syntax:
mysqldump -u[mysqluser] -p[password] [databasename] > [destinationfile.sql]

Example:
$ mysqldump -utestaccount -pg3pass employeefile > employeefile-dump.sql

Restoring MySQL Database

$ mysql -uaccount -ppassword employeefile < employeefile-dump.sql

Making Backup of the existing Table

Syntax:
create table <Table Destination> as select * from <Table Source>;

Example:
create table RADUSAGE_09082009 as select * from RADUSAGE;
Read rest of the content

Killing a Process in Linux

At times we encounter java process that won't stop by issuing the usual command "./shutdown.sh", or in some cases a multiple instance was created when the program was not properly restarted.

Below are the sample process status of the java in my linux box.

[root@geone bin]# ps -eaf | grep java
root 27272 1 0 Jul06 ? 00:00:22 /usr/java/j2sdk1.4.1_01/bin/java
root 27684 27273 0 Jul06 ? 00:03:01 /usr/java/j2sdk1.4.1_01/bin/java
root 27685 27273 0 Jul06 ? 00:04:23 /usr/java/j2sdk1.4.1_01/bin/java
root 27686 27273 0 Jul06 ? 00:03:01 /usr/java/j2sdk1.4.1_01/bin/java
root 27687 27273 0 Jul06 ? 00:03:01 /usr/java/j2sdk1.4.1_01/bin/java
root 27688 27273 0 Jul06 ? 00:03:04 /usr/java/j2sdk1.4.1_01/bin/java
root 27689 27273 0 Jul06 ? 00:03:04 /usr/java/j2sdk1.4.1_01/bin/java
root 27690 27273 0 Jul06 ? 00:03:04 /usr/java/j2sdk1.4.1_01/bin/java
root 27691 27273 0 Jul06 ? 00:03:01 /usr/java/j2sdk1.4.1_01/bin/java
root 27692 27273 0 Jul06 ? 00:03:01 /usr/java/j2sdk1.4.1_01/bin/java
root 27693 27273 0 Jul06 ? 00:03:02 /usr/java/j2sdk1.4.1_01/bin/java
root 27694 27273 0 Jul06 ? 00:03:01 /usr/java/j2sdk1.4.1_01/bin/java
root 27695 27273 0 Jul06 ? 00:03:04 /usr/java/j2sdk1.4.1_01/bin/java
root 2015 27273 0 Jul07 ? 00:00:00 /usr/java/j2sdk1.4.1_01/bin/java
root 2016 27273 0 Jul07 ? 00:00:00 /usr/java/j2sdk1.4.1_01/bin/java
root 2017 27273 0 Jul07 ? 00:00:00 /usr/java/j2sdk1.4.1_01/bin/java
root 2018 27273 0 Jul07 ? 00:00:00 /usr/java/j2sdk1.4.1_01/bin/java
root 2053 27273 0 Jul07 ? 00:00:00 /usr/java/j2sdk1.4.1_01/bin/java
root 2054 27273 0 Jul07 ? 00:00:00 /usr/java/j2sdk1.4.1_01/bin/java
root 2055 27273 0 Jul07 ? 00:00:02 /usr/java/j2sdk1.4.1_01/bin/java

root 2056 27273 0 Jul07 ? 00:00:00 /usr/java/j2sdk1.4.1_01/bin/java
root 24302 27273 0 Jul08 ? 00:03:00 /usr/java/j2sdk1.4.1_01/bin/java
root 24303 27273 0 Jul08 ? 00:03:00 /usr/java/j2sdk1.4.1_01/bin/java
root 24304 27273 0 Jul08 ? 00:02:59 /usr/java/j2sdk1.4.1_01/bin/java
root 24305 27273 0 Jul08 ? 00:02:58 /usr/java/j2sdk1.4.1_01/bin/java
root 24338 27273 0 Jul08 ? 00:02:58 /usr/java/j2sdk1.4.1_01/bin/java
root 24339 27273 0 Jul08 ? 00:02:59 /usr/java/j2sdk1.4.1_01/bin/java
root 24340 27273 0 Jul08 ? 00:02:58 /usr/java/j2sdk1.4.1_01/bin/java
root 24341 27273 0 Jul08 ? 00:02:59 /usr/java/j2sdk1.4.1_01/bin/java
root 24404 27273 0 00:06 ? 00:02:57 /usr/java/j2sdk1.4.1_01/bin/java

The best way to stop the process is to issue the command below:

$ kill -9 `ps -eaf | grep java | awk '{ print $2, $8}'`


Read rest of the content

A Note on Traffic Exchange Programs

We understand that our publishers are always looking for ways to attract interested users to their sites. But using third-party tools or services to increase your site traffic may lead to invalid clicks or impressions and result in your account being disabled. For this reason, we'd like to provide you with some guidance about this.

As many of you already know, our program policies strictly prohibit any means of artificially generating ad impressions or clicks, including third-party services such as paid-to-click, paid-to-surf, auto-surf, and click-exchange programs. These programs offer incentives for users to view web pages or click on ads, resulting in activity that is harmful to our advertisers.

We occasionally receive questions from publishers interested in using traffic exchanges to bring traffic to their site. While these services may help advertise your site, we don't recommend using them, as they may also result in similar invalid activity. We realize that you may have questions about a specific traffic service and whether it could potentially create invalid impressions or clicks. However, please understand that we're unable to comment on any particular third-party service.

As a parting note, we encourage you to read through our tips and guidelines and Webmaster Guidelines to help keep your account in good standing. These guidelines advise publishers to "Provide unique and relevant content that gives users a reason to visit your site first," and we feel this is ultimately the best way to attract more visitors to your site and build a truly loyal audience.

Adsense Blog


Read rest of the content
Your Ad Here
 
TNB | Deluxe Templates