Linux Tips

NTP – Howto make the clock show the correct time – LinuxReviews

Trước giờ toàn thích thì nhích, nên khi xong ròi chả nắm quái j  cả. Bi giờ ngẫm ra nếu bít trước mọi thứ thì có làm mới yên tâm được. 😛

Cái nì là lượm lặt trên Internet nhá pà con. Config NTP service cho Linux.

What the fudge?

There are two lines you should have in your configuration:

File: /etc/ntp.conf
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10

Biến server cho biết local system clock là 1 timeserver. Biến fudge cho biết server này được thiết lập ở mức 10. Nếu hệ thống của bạn đang kết nối ra Internet thì bạn nên dùng timeservers có stratum nhỏ hơn 10, và những server này sẽ được ưu tiên đồng bộ trước bởi vì nó có giá trị stratum thấp và đương nhiên có quyền ưu tiên cao hơn.

Tuy nhiên, nếu ban mất kết nối đến Internet thì khi đó các server này ko còn hiệu lực và bạn quay lại đồng bộ với Local clock. Sử dụng fudge để cho biết local clock có stratum là 10 khi đó ntp sẽ sử dụng local clock khi không có 1 external timeservers nào họat động. Điều này tốt bởi vì nó đảm bảo hệ thống của bạn khi mất kết nối Internet vẫn đảm bảo clock hệ thống không bị chạy lệch giờ.

Link : NTP – Howto make the clock show the correct time – LinuxReviews.

Dùng lệnh linux để phân tích log file của apache (linux command apache Log file analyzer)

Dùng lệnh linux để phân tích log file của apache (linux command apache Log file analyzer)
How to view log files?

Less can easily handle huge files.

Without line wrapping
% less -S access_log

Long lines wrapped
% less access_log

How to view compressed log files?
To save space log files are usually compressed.
Gzip (GNU zip) compressed file (.gz)
% gzip -dc access_log.gz | less

Bzip2 compressed file (.bz2)
% bzip2 -dc access_log.bz2 | less

How many lines (hits) there are in the log file?
Uncompressed log file
% wc -l access_log 33894

Gzip compressed log file
% gzip -dc access_log.gz | wc -l 33894

How many page views?
Uncompressed log file
% egrep ‘(.gif |.jpg |.png )’ access_log 2569

Compressed log file
% gzip -dc access_log.gz | egrep -vc ‘(.gif |.jpg |.png )’ 2569

How many hits today?
% grep -c `date ‘+%d/%b/%Y’` access_log 2569

How many unique visitors today?
% grep `date ‘+%d/%b/%Y’` access_log | cut -d" " -f1 | sort -u | wc -l 1196

How many hits in a particular day?
Uncompressed log file, e.g. January 1, 2009
% grep -c 01/Jan/2009 access_log 2569

Compressed log file, e.g. January 1, 2009
% gzip -dc access_log.gz | grep -c 01/Jan/2009 2569

What period is covered covered in the log?
Uncompressed log file
% head -1 access_log; tail -1 access_log foo.example – –
[30/Dec/2009:23:55:25 +0200] "GET /~vnntech/ … bar.example – –
[06/Jan/2009:23:53:37 +0200] "GET /~vnntech/rates.html …

Uncompressed log file
% gzip -dc access_log.gz | head -1 ; gzip -dc access_log.gz | tail -1
foo.example – – [30/Dec/2009:23:55:25 +0200] "GET /~vnntech/ …
bar.example – – [06/Jan/2009:23:53:37 +0200] "GET /~vnntech/rates.html

Are there missing dates?
Uncompressed log file
% cut -d" " -f4 access_log | cut -d"/" -f1 | uniq [30 [31 [01 [03 [04 [05 [06

Compressed log file
% gzip -dc wlog0101.gz | cut -d" " -f4 | cut -d"/" -f1 | uniq [30 [31 [01 [03 [04 [05 [06

How many corrupted log entries?
This is just a very quick and dirty way to check the log.
Uncompressed log file
% perl -ane ‘print $_ if (scalar (split /"/)) != 7’ access_log | wc -l

7

Compressed log file
% gzip -dc access_log.gz | perl -ane ‘print $_ if (scalar (split /"/)) != 7’ | wc -l

7

How does the line number 15927 or lines 15920 – 15929 look like?
Uncompressed log file

% grep -n ‘.*’ access_log | grep ‘^15927:’ 15927:foo.vnntech.com – – [20/Jan/2009:11:23:45 +0200] "GET …



% grep -n ‘.*’ access_log | grep ‘^1592.:’ 15920:foo.vnntech.com – –
[20/Jan/2009:11:23:40 +0200] "GET … 15921:foo.vnntech.com – –
[20/Jan/2009:11:23:41 +0200] "GET … 15922:foo.vnntech.com – –
[20/Jan/2009:11:23:41 +0200] "GET … …

Compressed log file

% gzip -dc access_log.gz | grep -n ‘.*’ | grep ‘^15927:’ 15927:foo.vnntech.com – – [20/Jan/2009:11:23:45 +0200] "GET …

% gzip -dc access_log.gz | grep -n ‘.*’ | grep ‘^1592.:’
15920:foo.vnntech.com – – [20/Jan/2009:11:23:40 +0200] "GET …
15921:foo.vnntech.com – – [20/Jan/2009:11:23:41 +0200] "GET …
15922:foo.vnntech.com – – [20/Jan/2009:11:23:41 +0200] "GET … …

How to figure out the bandwith consumption (in bytes)?
Today:
% grep `date ‘+%d/%b/%Y’` access_log | awk ‘{ s += $10 } END {print s}’ 13113756

This month:
% grep `date ‘+../%b/%Y’` access_log | awk ‘{ s += $10 } END {print s}’ 569477018

Used by Googlebot:
% grep googlebot access_log | awk ‘{ s += $10 } END {print s}’ 29832233

Used by some rogue user from IP-address 169.254.22.12:


% grep ^169.254.22.12 access_log | awk ‘{ s += $10 } END {print s}’ 46760880

How to delete partial GET requests from the log?
Partial content requests are usually generated by download managers to
speed the downloading of big files and Adobe Acrobat Reader to fetch PDF
documents page by page. In this example 206 requests generated by
Acrobat reader are deleted so that they don’t infate the hit count.

% grep -v ‘.pdf .* 206 ‘ access_log > new_log

How to compress a selected portion from a log?
Use gzip to compress log entries in May 2009
% grep ‘ [../May/2009:’ access_log | gzip -9c > access_log-2009-05.gz

Use bzip2 to compress log entries in May 2009
% grep ‘ [../May/2009:’ access_log | bzip2 > access_log-2009-05.bz2

See in real-time how the log file grows?
Using tail
% tail -f access_log

With less you must hit "F" (and Ctrl-C q to quit)
% less access_log

Nguồn : http://vnntech.com/forums/dung-lenh-linux-de-phan-tich-log-file-cua-apache-linux-command-apache-log-file-a-d104.htm

Some useful command on Linux/Unix

Today, I receive some request from our mate.

He wants to rename a file which begin a "-" character. haha. Searching on Google and I found this solution.
Thanks guys !

Rename file starting with a dash(-)

If having problem renaming a file that starts with a dash:

Since the file name begins with a ‘-‘ it looks like an option to the
command. You need to force it to not look like an option. Put a ./
in the front of it. Or give it the full file name path. Or tell the
command you are through with options by using the double dash to end
all option processing. This is common to most traditional UNIX
commands.

cp ./* /some/folder
cp — * /some/folder

And the same for other utilities too.

mv ./-stuff differentstuff
mv — -stuff differentstuff

theo : http://linux-journal.blogspot.com/2005/04/rename-file-starting-with-dash.html

How to get Physical Memory and CPU speed using unix commands?

a.Solaris:
$ /usr/sbin/prtconf |grep -i "Memory size"
$ swap -s
$ df -k
$ /usr/local/bin/top
$ vmstat 5 100
$ sar -u 2 100
$ iostat -D 2 100
$ mpstat 5 100
a. HP-UX 11.0:
$ grep Physical /var/adm/syslog/syslog.log
$ df -k
$ sar -w 2 100
$ sar -u 2 100
$ /bin/top
$ vmstat -n 5 100
$ iostat 2 100
$ top
b. AIX:

$ /usr/sbin/lsattr -E -l sys0 -a realmem
$ /usr/sbin/lsps -s
$ vmstat 5 100
$ iostat 2 100
$ /usr/local/bin/top # May not be installed by default in the server

c. Linux http://RedHat 7.1 and RedHat AS 2.1:
$ dmesg | grep Memory
$ vmstat 5 100
$ /usr/bin/top

2. PHYSICAL MEMORY AND SWAP SPACE

OS Specific Commands:
AIX:
/usr/sbin/lsattr -E -l sys0 -a realmem
/usr/sbin/lsps -s

HP-UX:
grep Physical /var/adm/syslog/syslog.log
/usr/sbin/swapinfo -t

Linux:
cat /proc/meminfo | grep MemTotal
/sbin/swapon -s

Solaris:
/usr/sbin/prtconf | grep "Memory size"
/usr/sbin/swap -s

Tru64:
vmstat -P| grep -i "Total Physical Memory ="
/sbin/swapon -s

*=========================================================================================================*
Linux:
On linux you dont have prtdiag but you can download a bunzip prtdiag file just google up you will find the download url.

file: prtdiag-1.2.tar.bz2
bunzip2 prtdiag-1.2.tar.bz2
tar xvf prtdiag-1.2.tar