DISCLAIMER : Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility.If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.
Uniq command in Unix
Uniq command in unix or linux system is used to suppress the duplicate
lines from a file. It discards all the successive identical lines except
one from the input and writes the output.
The syntax of uniq command is
The options of uniq command are:
The syntax of uniq command is
uniq [option] filename
The options of uniq command are:
- c : Count of occurrence of each line.
- d : Prints only duplicate lines.
- D : Print all duplicate lines
- f : Avoid comparing first N fields.
- i : Ignore case when comparing.
- s : Avoid comparing first N characters.
- u : Prints only unique lines.
- w : Compare no more than N characters in lines
First create the following example.txt file in your unix or linux operating system.
# cat example.txt Unix operating system unix operating system unix dedicated server linux dedicated server
1. Suppress duplicate lines
The default behavior of the uniq command is to suppress the duplicate line. Note that, you have to pass sorted input to the uniq, as it compares only successive lines.
# uniq example.txt unix operating system unix dedicated server linux dedicated server
If the lines in the file are not in sorted order, then use the sort command and then pipe the output to the uniq command.
# sort example.txt | uniq
2. Count of lines.
The -c option is used to find how many times each line occurs in the file. It prefixes each line with the count.
# uniq -c example.txt 2 unix operating system 1 unix dedicated server 1 linux dedicated server
3. Display only duplicate lines.
You can print only the lines that occur more than once in a file using the -d option.
# uniq -d example.txt unix operating system # uniq -D example.txt unix operating system unix operating system
The -D option prints all the duplicate lines.
4. Skip first N fields in comparison.
The -f option is used to skip the first N columns in comparison. Here the fields are delimited by the space character.
# uniq -f2 example.txt unix operating system unix dedicated server
In the above example the uniq command, just compares the last fields. For the first two lines, the last field contains the string "system". Uniq prints the first line and skips the second. Similarly it prints the third line and skips the fourth line.
5. Print only unique lines.
You can skip the duplicate lines and print only unique lines using the -u option
# uniq -u example.txt unix dedicated server linux dedicated server
Using iptrace command in AIX
Creating, formatting, and reading packet traces is sometimes required to resolve problems. However, the most appropriate tool varies, depending on operating system.
The iptrace command can be very useful to find out what network traffic flows to and from an AIX system.
You can use any combination of these options, but you do not need to use them all:
-a Do NOT print out ARP packets.
-s [source IP] Limit trace to source/client IP address, if known.
-d [destination IP] Limit trace to destination IP, if known.
-b Capture bidirectional network traffic (send and receive packets).
-p [port] Specify the port to be traced.
-i [interface] Only trace for network traffic on a specific interface.
Examples:
1. Run iptrace on AIX interface en1 to capture port 80 traffic to file trace.out from a single client IP to a server IP:
# iptrace -a -i en1 -s clientip -b -d serverip -p 80 trace.out
This trace will capture both directions of the port 80 traffic on interface en1 between the clientip and serverip and sends this to the raw file of trace.out.
2. To stop the trace:
# ps -ef|grep iptrace
# kill <PID>
3. The ipreport command can be used to transform the trace file generated by iptrace to human readable format:
# ipreport trace.out > trace.report
4. To start the iptrace daemon with the System Resource Controller (SRC), enter:
startsrc -s iptrace -a "/tmp/nettrace"
To stop the iptrace daemon with SRC enter the following:
stopsrc -s iptrace
5. To record packets coming in and going out to any host on every interface, enter the command in the following format:
iptrace /tmp/nettrace
The recorded packets are received on and sent from the local host. All packet flow between the local host and all other hosts on any interface is recorded. The trace information is placed into the /tmp/nettrace file.
6. To record packets received on an interface from a specific remote host, enter the command in the following format:
iptrace -i en0 -p telnet -s airmail /tmp/telnet.trace
The packets to be recorded are received on the en0 interface, from remote host airmail, over the telnet port. The trace information is placed into the /tmp/telnet.trace file.
7. To record packets coming in and going out from a specific remote host, enter the command in the following format:
iptrace -i en0 -s airmail -b /tmp/telnet.trace
The packets to be recorded are received on the en0 interface, from remote host airmail. The trace information is placed into the /tmp/telnet.trace file.
The iptrace command can be very useful to find out what network traffic flows to and from an AIX system.
You can use any combination of these options, but you do not need to use them all:
-a Do NOT print out ARP packets.
-s [source IP] Limit trace to source/client IP address, if known.
-d [destination IP] Limit trace to destination IP, if known.
-b Capture bidirectional network traffic (send and receive packets).
-p [port] Specify the port to be traced.
-i [interface] Only trace for network traffic on a specific interface.
Examples:
1. Run iptrace on AIX interface en1 to capture port 80 traffic to file trace.out from a single client IP to a server IP:
# iptrace -a -i en1 -s clientip -b -d serverip -p 80 trace.out
This trace will capture both directions of the port 80 traffic on interface en1 between the clientip and serverip and sends this to the raw file of trace.out.
2. To stop the trace:
# ps -ef|grep iptrace
# kill <PID>
3. The ipreport command can be used to transform the trace file generated by iptrace to human readable format:
# ipreport trace.out > trace.report
4. To start the iptrace daemon with the System Resource Controller (SRC), enter:
startsrc -s iptrace -a "/tmp/nettrace"
To stop the iptrace daemon with SRC enter the following:
stopsrc -s iptrace
5. To record packets coming in and going out to any host on every interface, enter the command in the following format:
iptrace /tmp/nettrace
The recorded packets are received on and sent from the local host. All packet flow between the local host and all other hosts on any interface is recorded. The trace information is placed into the /tmp/nettrace file.
6. To record packets received on an interface from a specific remote host, enter the command in the following format:
iptrace -i en0 -p telnet -s airmail /tmp/telnet.trace
The packets to be recorded are received on the en0 interface, from remote host airmail, over the telnet port. The trace information is placed into the /tmp/telnet.trace file.
7. To record packets coming in and going out from a specific remote host, enter the command in the following format:
iptrace -i en0 -s airmail -b /tmp/telnet.trace
The packets to be recorded are received on the en0 interface, from remote host airmail. The trace information is placed into the /tmp/telnet.trace file.
YUM in RHEL
Yum or Yellow dog Update, Modified is a package manager that was developed by Duke University to improve the installation of RPMs.
Yum searches numerous repositories for packages and their dependencies so they may be installed together in an effort to alleviate dependency issues. Red Hat Enterprise Linux 5 uses Yum to fetch packages and install RPMs.
Yum uses a configuration file at /etc/yum.conf. Also refer yum(8) man page for more information.
There are multiple ways by which you can install a repository on the system and install/update packages :
Yum searches numerous repositories for packages and their dependencies so they may be installed together in an effort to alleviate dependency issues. Red Hat Enterprise Linux 5 uses Yum to fetch packages and install RPMs.
Yum uses a configuration file at /etc/yum.conf. Also refer yum(8) man page for more information.
There are multiple ways by which you can install a repository on the system and install/update packages :
- Add an existing repository.
- Setup a new repository having packages populated from ISO's downloaded from RHN.
- Register the system on RHN and subscribe to the channels depending on the subscription you have.
To automatically install software from the DVD I would like to use YUM, but I have to set it up first. There is a main configuration file - yum.conf which resides in /etc. This is the default content of it:
# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3
Next we need the Media ID from the DVD. It can be obtained from a file call media.repo from the DVD. First mount the DVD:
# mkdir -p /mnt/dvd
# mount /dev/sr0 /mnt/dvd
Or mount the ISO file:
# mkdir -p /mnt/dvd
# mount /root/rhel6.iso /mnt/dvd -o loop
Get Media ID from DVD:
# cat /mnt/dvd/media.repo
[InstallMedia]
name=Red Hat Enterprise Linux 6.0
mediaid=0123456789.012345
...
Now configure /etc/yum.repos.d/file.repo and add the DVD (or the ISO file) as a repository and add /mnt/dvd as baseurl:
# cat /etc/yum.repos.d/file.repo
[dvd]
mediaid=0123456789.012345
name=DVD
baseurl=file:///mnt/dvd
enabled=1
gpgcheck=0
Check if it accept the repository:
# yum repolist
Loaded plugins: rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
dvd | 3.7 kB 00:00 ...
dvd/primary_db | 2.9 MB 00:00 ...
Install a package from the repository (e.g. tree):
# yum install tree
Loaded plugins: rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.5.3-2.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
Package Arch Version Repository Size
tree x86_64 1.5.3-2.el6 dvd 36 k
Transaction Summary
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 36 k
Installed size: 65 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : tree-1.5.3-2.el6.x86_64
1/1
Installed:
tree.x86_64 0:1.5.3-2.el6
Complete! Just keep in mind that you always have to mount the DVD or the ISO file before you can install any software via YUM.
Yum must be running as root. Here are some useful commands:
1) Install a package:
# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3
Next we need the Media ID from the DVD. It can be obtained from a file call media.repo from the DVD. First mount the DVD:
# mkdir -p /mnt/dvd
# mount /dev/sr0 /mnt/dvd
Or mount the ISO file:
# mkdir -p /mnt/dvd
# mount /root/rhel6.iso /mnt/dvd -o loop
Get Media ID from DVD:
# cat /mnt/dvd/media.repo
[InstallMedia]
name=Red Hat Enterprise Linux 6.0
mediaid=0123456789.012345
...
Now configure /etc/yum.repos.d/file.repo and add the DVD (or the ISO file) as a repository and add /mnt/dvd as baseurl:
# cat /etc/yum.repos.d/file.repo
[dvd]
mediaid=0123456789.012345
name=DVD
baseurl=file:///mnt/dvd
enabled=1
gpgcheck=0
Check if it accept the repository:
# yum repolist
Loaded plugins: rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
dvd | 3.7 kB 00:00 ...
dvd/primary_db | 2.9 MB 00:00 ...
Install a package from the repository (e.g. tree):
# yum install tree
Loaded plugins: rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.5.3-2.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
Package Arch Version Repository Size
tree x86_64 1.5.3-2.el6 dvd 36 k
Transaction Summary
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 36 k
Installed size: 65 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : tree-1.5.3-2.el6.x86_64
1/1
Installed:
tree.x86_64 0:1.5.3-2.el6
Complete! Just keep in mind that you always have to mount the DVD or the ISO file before you can install any software via YUM.
Yum must be running as root. Here are some useful commands:
1) Install a package:
yum install package
Example:yum install httpd
2) Remove a package:yum remove package
Example:yum remove httpd
3) Update a package:yum update package
Example:yum update httpd
4) Search for a package:yum search package
Example:yum search httpd
5) Find information about a package:yum info package
Example:yum info httpd
6) List packages containing a certain term:yum list term
Example:yum list httpd
7) Find what package provides a particular file:yum whatprovides 'path/filename'
Example:yum whatprovides 'etc/httpd.conf'
yum whatprovides '*/libXp.so.6'
8) Update all installed packages with kernel package :yum update
Example:yum update
9) To update a specific package:yum update <package-name>
Example:yum update openssh-server