display the Nth line of a file
if you want to display or view a particular line for eg 5th line of a file then u can use sed for that..
[root@server1 ~]# sed -n ‘14p’ /etc/passwd
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
in the above example it displays the 14 line of the file /etc/passwd
error restarting dovecot
On some servers Dovecot doesn’t start automatically after reboot, or even sometimes while configuring itself it wont start,
if the error is like while giving the command
# service dovecot restart
Starting dovecot: Fatal: Listen(143) failed :Address already in use
try the following commands to check whether the port is already in use
[root@station5 ~]# netstat -a | grep imap
if it returns nothing then try
[root@station5 ~]# lsof -i :143
where lsof is the command to list information about files opened by processes then you will get the result if anyother process occupied the port 143
then make the port free by stop that process
for example
[root@station5 ~]# lsof -i :143
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
cyrus-mas 5115 cyrus 11u IPv6 22457 TCP *:imap (LISTEN)
cyrus-mas 5115 cyrus 14u IPv4 22459 TCP *:imap (LISTEN)
imapd 5122 cyrus 4u IPv6 22457 TCP *:imap (LISTEN)
imapd 5127 cyrus 4u IPv4 22459 TCP *:imap (LISTEN)
imapd 5131 cyrus 4u IPv6 22457 TCP *:imap (LISTEN)
imapd 5133 cyrus 4u IPv4 22459 TCP *:imap (LISTEN)
imapd 5135 cyrus 4u IPv6 22457 TCP *:imap (LISTEN)
imapd 5136 cyrus 4u IPv6 22457 TCP *:imap (LISTEN)
imapd 5137 cyrus 4u IPv6 22457 TCP *:imap (LISTEN)
imapd 5140 cyrus 4u IPv4 22459 TCP *:imap (LISTEN)
imapd 5141 cyrus 4u IPv4 22459 TCP *:imap (LISTEN)
imapd 5142 cyrus 4u IPv4 22459 TCP *:imap (LISTEN)
then stop the service of cyrus-imapd as
service cyrus-imapd stop
if you dont know the service for cyrus then get it easily by
[root@station5 ~]# chkconfig –list | grep cyrus
cyrus-imapd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
and then try restarting the dovecot
[root@station5 ~]# service dovecot restart
Stopping Dovecot Imap: [FAILED]
Starting Dovecot Imap: [ OK ]
that’s all ok…..
sum of digit
if [ $# -ne 1 ]
then
echo “Usage: $0 number”
echo ” I will find sum of all digit for given number”
echo ” For eg. $0 123, I will print 6 as sum of all digit (1+2+3)”
exit 1
fi
n=$1
sum=0
d=0
while [ $n -gt 0 ]
do
d=`expr $n % 10`
sum=`expr $sum + $d`
n=`expr $n / 10`
done
echo “Sum of digit for number is $sum”
securing the files
this tip is about two powerful utilities that ensure the security of your data. Let us assume that you have a whole lot of files that you want to protect against mischievous tampering or alteration.
1)With the GPG program you can digitally ’sign’ files, & ensure tamper detection easily. With GPG you can ’sign’ only one file at a time.
2)With md5 you can create checksums of several files at a time (using the md5sum program).But if intruders can tamper with the file,they can also tamper with the md5 checksum, & destroy all traces of their mischief.
Any modification to any of the files is detected by verifying the md5 checksum. Any modification to the md5 checksum file gets detected by verification using GPG, the digital signature of the checksum file.
Select some files
# ls -l
-rw-r–r– 1 root root 0 Jan 5 07:21 testfile1
-rw-r–r– 1 root root 0 Jan 5 07:21 testfile2
-rw-r–r– 1 root root 0 Jan 5 07:21 testfile3
step: 1
create the md5sums to fhat files & send the output to md5sum_file
# md5sum testfile* >> mdsum_file
mdsum_file contains md5sum of that 3 files. that entries are
d41d8cd98f00b204e9800998ecf8427e testfile1
d41d8cd98f00b204e9800998ecf8427e testfile2
d41d8cd98f00b204e9800998ecf8427e testfile3
first column is the md5sum of the file named in the second column.
Step 2:
Check the md5sums of that files :
# md5sum -c md5sum_file
output are:
testfile1: ok
testfile2: ok
testfile3: ok
Now change one of the files(say testfile1) & check
# md5sum -c md5sum_file
output file:
testfile1: failed
testfile2: ok
testfile3: ok
So alterations made to any file can be spotted easily by using md5sum.
Step 3:
Now we need to protect this md5sum_file. The cunning criminals who tampered with your files can also tamper with the md5sum_file. So now we use GPG(an encryption tool) to digitally sign the md5sum_file.
The GPG signature is done using a secret key known only to you. You can learn about GPG at http://www.gnupg.org/ . The digital signature consists of an encrypted form of the hash digest of the file,which is signed. Any change to the file will render its digital signature ineffective. You can verify the digital signature using the public key of the person who signed the file. Thus any change to the md5sum_file will get noticed on verification of its digital signature.
For instance md5sum does not go into directories. following command will help you
find $1 -type f -print0 | xargs -0 md5sum -b > md5file.md5
PDFs of man pages
Convert the man pages to PDF format:
man -t | ps2pdf – > .pdf
example:
man -t sed | ps2pdf – > sed.pdf
Find and Replace strings in any file
1) if you want to find a string with the name “jeva”, & replace with “jeeva”,you can use
# sed -i s/expression/replacement/g file.txt
example:
# sed -i s/jeva/jeeva/g mytestfile
where i-insert, s-substitution, g-space
2)if you want to take a backup before replacing
# sed -ibackup s/jeva/jeeva/g mytestfile
here the changes are made in the mytestfile, original content will be in the mytestfilebackup
file.if you use “i” option you can give any name for backup option.
Example
# sed -iback s/jeva/jeeva/g mytestfile
it will create mytestfileback as a backup file
# sed -ib s/jeva/jeeva/g mytestfile
it will create mytestfileb as a backup file
Splitting and merging large files
You can split a big file of smaller parts of 100MB each, as follows:
# split -b 100m bigfile parts_
to join them in a linux machine,use
# cat parts_* > bigfile
What do you when the monitor goes blank
In Linux, we have found that after some time, the monitor goes into power-saving mode, ie., it goes blank To modify this setting, you need to run the following command:
# xset dpms 1800 2400 3600
this indicates that the monitor screen goes blank after 30 minutes(1800 seconds),goes into power saving mode after 40 minutes(2400 seconds) and switches off after 60 minutes(3600 seconds).
You can also stop this feature
#xset s off
Virtual LAN configuration
You can create a VLAN on Linux by executing the following commands:
vconfig add
ifconfig . netmask
ifconfig . up
For example:
vconfig add eth0 6
ifconfig eth0.5 192.168.1.6 netmask 255.255.255.0
ifconfig eth0.6 up
You can view the traffic of that VLAN by executing the following command:
cat /proc/net/vlan/eth0.6
like you can configure 2048 VLANs for one physical interface.
Create your own Live CD ISO
Go to this url:
http://custom.nimblex.net
The base distro size is 200 mb,which is shown as a green bar on the top of the NimbleX welcome Live cd generator page,
select
type of configuration
software selection
walpapper selection
user creation
Remember that custom NimbleX generates a cd-size distro.Hence,700mb of software is all you get.
The final screen after the language selection is a summary of all the choices made. It also enables you to go back & change your selections if required.
Finally, the ISO is created & it’s time to download. This ISO image remains on the server for 12 hours. So you must finish downloading within the allocated time.
type this command in terminal & download:
wget -c http://custom.nimblex.net/data/generated-iso/NimbleX-34197Crp.iso
-
Archives
- August 2009 (1)
- June 2009 (1)
- March 2009 (1)
- January 2009 (7)
- December 2008 (7)
-
Categories
-
RSS
Entries RSS
Comments RSS