Wednesday, 29 August 2012


Procedure to mount ISO images under Linux



An ISO image is an archive file (disk image) of an optical disc using a conventional ISO (International Organization for Standardization) format. ISO image files typically have a file extension of .ISO. The name "ISO" is taken from the ISO 9660 file system used with CD-ROM media, but an ISO image can also contain UDF file system because UDF is backward-compatible to ISO 9660.
You can mount an ISO images via the loop device under Linux. It is possible to specify transfer functions (for encryption/decryption or other purposes) using loop device.

1) You must login as a root user, if not root user then switch to root user using following command:
$ su -

2) Create the directory i.e. mount point:
# mkdir -p /mnt/disk

3) Use mount command as follows to mount iso file called disk1.iso:
# mount -o loop disk1.iso /mnt/disk

To mount the ISO image file.iso to the mount point /mnt/test use this command:
mount -o loop -t iso9660 file.iso /mnt/disk
Syntax: # mount ISOFILE MOUNT-POINT -o loop
$ su -

# mkdir /tmp/mnt

# mount -o loop /downloads/ubuntu-9.04-desktop-i386.iso /tmp/mnt 

# cd /tmp/mnt
# ls -l

4) Change directory to list files stored inside an ISO image:
# cd /mnt/disk
# ls -l

==========================================

Mount a CD ISO Image

We'll use the regular mount command to mount the ISO image into a folder, just like you would do with a regular drive. The difference is that we pass the -o loop command to specify the loop module, which can handle ISO images.

$sudo mount filename.iso /media/iso -t iso9660 -o loop

Of course you should make sure that you have created the /media/iso folder ahead of time.

Mount a DVD ISO Image

When mounting ISO images of DVDs, you might have to use the UDF type instead of ISO.

$sudo mount filename.iso /media/iso -t udf -o loop

Monday, 27 August 2012

Examples for Viewing Huge Log Files in Linux/Unix ?


Example 1: Display specific lines (based on line number) of a file using sed command

View only the specific lines mentioned by line numbers.
Syntax: $ sed -n -e Xp -e Yp FILENAME
  • sed : sed command, which will print all the lines by default.
  • -n : Suppresses output.
  • -e CMD : Command to be executed
  • Xp: Print line number X
  • Yp: Print line number Y
  • FILENAME : name of the file to be processed.
The example mentioned below will print the lines 120, 145, 1050 from the syslog.
$ sed -n -e 120p -e 145p -e 1050p /var/log/syslog
In the following example,  you can view the content of var/log/cron from line number 101 to 110.
  • M – Starting line number
  • N – Ending line number
Syntax: sed -n M,Np FILENAME

$ sed -n 101,110p /var/log/cron

Example 2: Display first N lines of a file using head command


This example displays only first 15 lines of /var/log/maillog file. Change 15 to 10 to display the first 10 lines of a log file.
Syntax: head -n N FILENAME

$ head -n 15 /var/log/maillog

Example 3: Ignore last N lines of a file using head command

This example shows how to ignore the last N lines, and show only the remaining lines from the top of file.
The following example will display all the lines of the /var/log/secure except the last 250 lines.
Syntax: head -n -N FILENAME

$ head -n -250 /var/log/secure

Example 4: Display last N lines of the file using tail command

This example displays only last 50 lines of /var/log/messages file. Change 50 to 100 to display the last 100 lines of the log file.
Syntax: tail -n N FILENAME

$ tail -n 50 /var/log/messages

Example 5: Ignore first N-1 lines of the file using tail command

This example shows how to ignore the first N-1 lines and show only the remaining of the lines.
The following example ignores the 1st four lines of the /etc/xinetd.conf, which contains only the comments.
Syntax: tail -n +N FILENAME

$ tail -n +5 /etc/xinetd.conf
defaults
{
        instances               = 60
        log_type                = SYSLOG authpriv
        log_on_success          = HOST PID
        log_on_failure          = HOST
        cps                     = 25 30
}
includedir /etc/xinetd.d

Example 6: View growing log file in real time using tail command

This is probably one of the most used command by sysadmins.To view a growing log file and see only the newer contents use tail -f as shown below.
The following example shows the content of the /var/log/syslog command in real-time.
Syntax: tail -f FILENAME

$ tail -f /var/log/syslog

Example 7: Display specific lines (based on line number) of a file using head and tail command

The example below will display line numbers 101 – 110 of /var/log/anaconda.log file
  • M – Starting line number
  • N – Ending line number
Syntax: cat file | tail -n +N | head -n (M-N+1)

$ cat /var/log/anaconda.log | tail -n +101 | head -n 10
  • cat : prints the whole file to the stdout.
  • tail -n +101 : ignores lines upto the given line number, and then start printing lines after the given number.
  • head -n 10 : prints the first 10 line, that is 101 to 110 and ignores the remaining lines.

Example 8: Display lines matching a pattern, and few lines following the match.

The following example displays the line that matches “Initializing CPU” from the /var/log/dmesg and 5 lines immediately after this match.
# grep "Initializing CPU#1" /var/log/dmesg
Initializing CPU#1
[Note: The above shows only the line matching the pattern]

# grep -A 5 "Initializing CPU#1" dmesg
Initializing CPU#1
Calibrating delay using timer specific routine.. 3989.96 BogoMIPS (lpj=1994982)
CPU: After generic identify, caps: bfebfbff 20100000 00000000 00000000
CPU: After vendor identify, caps:  bfebfbff 20100000 00000000 00000000
monitor/mwait feature present.
CPU: L1 I cache: 32K, L1 D cache: 32K
[Note: The above shows the line and 5 lines after the pattern matching]
As explained in our previous grep command article, the following operations are possible.
  • Viewing specific lines identified by patterns, which is grep’s default functionality.
  • Viewing only the matched characters.
  • Viewing N lines after the match with -A option.
  • Viewing N lines before the match with -B option.
  • Viewing N lines around the match with -C option.

Example 9: Displaying specific bytes from a file.

The following example explains how to display either the top 40 or the last 30 bytes of a file.

Display first 40 bytes from syslog.

$ head -c40 /var/log/syslog

Display last 30 bytes from syslog.

$ tail -c30 /var/log/syslog

Example 10: Viewing compressed log files

After a specific time all the system log files are rotated, and compressed. You can uncompress it on the fly, and pipe the output to another unix command to view the file as explained below.
  • Display the first N lines of a compressed file.
    $ zcat file.gz | head -250
  • Display the last N lines of a compressed file.
    $ zcat file.gz | tail -250
  • Ignoring the last N lines of a compressed file.
    $ zcat file.gz | head -n -250
  • Ignoring the first N lines of a compressed file.
    $ zcat file.gz | tail -n +250
  • Viewing the lines matching the pattern
    $ zcat file.gz | grep -A2 'error'
  • Viewing particular range of lines identified by line number.
    $ zcat file.gz | sed -n -e 45p -e 52p

How to read a .gz file, one line at a time and Power of Z command ?

#gzcat test1.gz

#gzcat my_tar_archive.tgz | tar -tvf -


[Solved] Read a .gz file line by line without using gzcat

Hi all
Is there a way to read and process a gzip file line by line similar to a text file without using gzcat..

while processing a text file we will usually use the logic 

Code:
exec<sample.txt
while read line
do 
echo $line
done

Since gzip, gunzip and gzcat are the same executable, so if you have one, you have all, available all over as a binary or source. Normally, you do something like this:

gunzip < file.gz | while read ln
do
. . .
done
Compatability: uncompress will not work on .gz, but gunzip, gzcat work on compress output (.Z).


=================================================

The Power of Z Commands – Zcat, Zless, Zgrep, Zdiff Examples ?

You can do the following normal file operations on the compressed file
  1. Viewing the compressed file with zcat.
  2. Paging the compressed file with zless / zmore.
  3. Searching inside the compressed file with zgrep / zegrep.
  4. Comparison of file using zdiff / zcmp

The old way...

Let us say you have a file called data..txt.gz. To display file you can type:
gzip -d data.txt.gz
cat data.txt
less data.txt

The new way...

Just use zless command:
zless data.txt.gz
zmore data.txt.gz

zcat command

Concatenate compressed files and print on the screen:
zcat file.gz

zdiff / zcmp command

Compare compressed files:
zdiff file1.gz file2.gz
zcmp file1.gz file2.gz

zegrep / zfgrep / zgrep command

Search compressed files for a regular expression:
zegrep -w '^word1|word2' file.gz
zgrep 'word' file.gz

zless / zmore commands

zmore and zless is a filter which allows examination of compressed or plain text files one screenful at a time on a screen. zmore works on files compressed with compress, pack or gzip, and also on uncompressed files. If a file does not exist, zmore looks for a file of the same name with the addition of a .gz, .z or .Z suffix.
zmore file.gz
zless file.gz

znew command

Znew recompresses files from .Z (compress) format to .gz (gzip) format. If you want to recompress a file already in gzip format, rename the file to force a .Z extension then apply znew.
znew file.Z

zdump command

zdump command prints the current time in each zonename named on the command line. Let us say your current time zone is IST (Indian standard time) and like to see time current time for Los Angeles (USA - PDT), enter:
date
Output:
Fri Aug 31 20:51:39 IST 2007
Now display Los Angeles current time :
zdump /usr/share/zoneinfo/America/Los_Angeles
Output:
/usr/share/zoneinfo/America/Los_Angeles  Fri Aug 31 08:20:31 2007 PDT

zipgrep command

Search files in a ZIP archive for lines matching a pattern:
zipgrep *.cpp basesys.zip
Example 1: View Compressed File and Uncompress with zcat
Compressing a file using gzip creates a compressed file with *.gz extension. You can view a compressed file with zcat with the following way. Which would be as same as the uncompressed file operation ‘cat filename’. zcat uncompresses the file and shows it in the stdout.
$ zcat filename.gz | more
$ ls -l big-file.*
-rw-r--r-- 1 ramesh ramesh 24853275 May  9 15:14 big-file.txt

$ gzip big-file.txt 
[Note: Compress the file]

$ ls -l big-file.*
-rw-r--r-- 1 ramesh ramesh 9275204 May  9 15:14 big-file.txt.gz

$ zcat big-file.txt.gz 
[Note: View the file without uncompressing it]

zcat big-file.txt.gz > big-file.txt
[Note: Uncompress the file]

Example 2: View a gzipped file which don’t have the gz suffix.

You can uncompress a gzipped file which don’t have the gz suffix. If you try to uncompress a gzipped file which don’t have the gz suffix with “gunzip” or “gzip -d” command you will face the following error.
gunzip: auth.log: unknown suffix -- ignored
But this zcat will uncompress the file and shows the content as shown below.
$ cat > test-file.txt
This is a test file used for gunzip and zcat testing

zcat is awesome command.  

$ gzip test-file.txt

$ mv test-file.txt.gz test-file-no-ext

$ gzip -d test-file-no-ext
gzip: test-file-no-ext: unknown suffix -- ignored

$ zcat test-file-no-ext
This is a test file used for gunzip and zcat testing

zcat is awesome command.

Example 3: Display the file content without worrying about whether it is compressed or not

When you are not sure whether a file is compressed or not, you can still view the file without worrying about it’s compression status as shown below.

In this example, If the input-file is compressed zcat will display the content by uncompressing it. If the input-file is not compressed zcat will display the content as it is.
$ zcat -f input-file

Example 4: Paging the compressed file with zless / zmore.

You can paginate a compressed file with zless command or zmore command as shown below.

$ zcat filename.gz | more
$ zcat filename.gz | less

(or)

$ zless filename.gz
$ zmore filename.gz
Example 5: Searching inside the compressed file with zgrep / zegrep.
You can search inside a compressed file with zgrep / zegrep as shown below. This would be as same as the uncompressed file operation ‘grep -i filename’. All the options to the zgrep command will be passed to grep, and the file will be fed to grep command. It may uncompress and feed the file to grep command if needed.
$ cat > test-file.txt
gzip, gunzip, zcat - compress or expand files
zless - file perusal filter for crt viewing of compressed text
zcmp, zdiff - compare compressed files

$ grep -i less test-file.txt
zless - file perusal filter for crt viewing of compressed text

$ gzip test-file.txt

$ zgrep -i less test-file.txt.gz
zless - file perusal filter for crt viewing of compressed text

Example 6: Comparison of file using zdiff / zcmp
You can compare two compressed files with zdiff / zcmp as shown below. This would be same as the uncompressed file operation ‘diff file1 file2′.
$ cat > file1.txt
This is line one
This is line two

$ cat > file2.txt
This is line 1
This is line two

$ diff file1.txt file2.txt
1c1
< This is line one
---
> This is line 1

$ gzip file1.txt file2.txt 

$ zdiff file1.txt.gz file2.txt.gz
1c1
< This is line one
---
> This is line 1

Apache server is very slow ?


Apache server is very slow..


Hi,


I have a development server on rhel5.5 and running apache and database server is mysql(LAMP)with same configuration. When opening the page it's becomes very slow. I found that memory uses was high by httpd with lots of process. I have restarted the httpd and its working. Again after sometime situation becomes same. Also on database side there was no any lock process.

Its a ESX VM, previous memeory was 1024, increased it to 2048, but no luck.


What may be cause for this slowness??


Thanks-

shankar

Apache server is very slow..

Q: "Memory use was high". But were you actually paging, or did everything fit in available RAM (either 1024 or 2048)?



Q: Remember, in a VM, there is no such thing as "physical RAM". Furthermore, ESX server has something called "balloon memory". Perhaps ESX itself might be overloaded?


Coming back to your original question -


SUGGESTIONS:

1. Compare retrieval times for a blank page vs. the HTML that's taking a long time.

If the blank HTML is fast, see what's going on with your actual page.

Look at stuff like a) database queries, b) large images and c) large Javascript overhead

2. Look at performance tools like "top", "uptime", "iostat", etc etc to evaluate performance at the system level (independent of Apache) and see what you come up with.

Apache server is very slow..

kill the httpd and restart it

Apache server is very slow..


Also, did you check your apache error log and try too see if it pops up any warning during restarting apache ?
Yes, using "top" and "ps -ef | grep httpd", we can find that 10-25 httpd process running and each process taking 3 to 4 mb memory. After restarting httpd its running fine for few times. But after sometimes same problem arise.



Thanks-

Shankarv

Apache server is very slow..

What are the values of following variables in httpd.conf ?

MaxClients

MinSpareThreads

MaxSpareThreads

ThreadsPerChild

Apache server is very slow..

Hi,

Plz find the below values for httpd.conf


StartServers 2

MaxClients 150

MinSpareThreads 25

MaxSpareThreads 75

ThreadsPerChild 25

MaxRequestsPerChild 0



Thanks-

Shankar


Apache server is very slow..

You also don't mention what the disk structure of the underlying ESX server is. I have found that the most common reason for poor performance on a VM is when the host has a single (or small number drives in RAID) installed locally. Generally speaking with modern hardware it is very easy to over allocate the resources. This is especially true if you are running a number of different isolated database instances across the VMs.

Apache server is very slow..

Hi,

In our environment, disk is comming from storage(EMC) and no any raid configuration is there.

We have 4 ESX hosts. I have also moved from one host to another to check the performance but no luck.

Mysql database having only one instance. We have also increase the RAM to 2048 but swap is same(1024) as there is no space available.



Thanks-

Shankar