man hier
man hier
Whenever you want to check if a file system is mounted and perform some action in you script based on this, the simplest and most accurate way to do it in Linux is to check /proc/mounts:
if grep -qs ‘/mnt/sda2′ /proc/mounts; then
echo “fs mounted”
else
echo “fs not mounted”
fi
I’ve recently installed a new LDAP server on Debian Lenny and I wanted to disable IPv6 as it is unnecessary for me in this moment. With netstat I checked the listening processes:
netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN 2226/slapd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2215/sshd
tcp6 0 0 :::389 :::* LISTEN 2226/slapd
tcp6 0 0 :::22 :::* LISTEN 2215/sshd
and lsmod showed something like this:
Module Size Used by
ipv6 235364 12
...
So, to disable IPv6 I changed /etc/modprobe.d/aliases:
...
# alias net-pf-10 ipv6
# Disable ipv6
alias net-pf-10 off
alias ipv6 off
...
I also disabled these lines in /etc/hosts to avoid confusions:
...
## The following lines are desirable for IPv6 capable hosts
#::1 localhost ip6-localhost ip6-loopback
#fe00::0 ip6-localnet
#ff00::0 ip6-mcastprefix
#ff02::1 ip6-allnodes
#ff02::2 ip6-allrouters
#ff02::3 ip6-allhosts
Finally I restarted the server.
shutdown -r now
Now the situation is like this:
netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN 2233/slapd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2216/sshd
lsmod|grep ipv6
...
No IPv6.
Today we are going to take a quick look at dig. According to the man pages:
dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use and clarity of output.
Let’s see how to lookup the DNS servers for the domain karkomaonline.com:
dig karkomaonline.com -t ns
The -t option specifies the query type (a, any, mx, ns, txt… ), being a the default. The -t ns option will look-up the Name Servers for the domain karkomaonline.com. You should get something like this:
; <<>> DiG 9.4.2-P2 <<>> karkomaonline.com -t ns
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4825
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;karkomaonline.com. IN NS
;; ANSWER SECTION:
karkomaonline.com. 172800 IN NS dns010.d.register.com.
karkomaonline.com. 172800 IN NS dns024.c.register.com.
karkomaonline.com. 172800 IN NS dns071.a.register.com.
karkomaonline.com. 172800 IN NS dns150.b.register.com.
;; ADDITIONAL SECTION:
dns010.d.register.com. 48 IN A 216.21.236.10
;; Query time: 172 msec
;; SERVER: 192.168.1.9#53(192.168.1.9)
;; WHEN: Wed Apr 15 22:46:35 2009
;; MSG SIZE rcvd: 152
The interesting part is the ANSWER SECTION, that lists the name servers for the mentioned domain. You can get a shorter output of the same command:
dig karkomaonline.com -t ns +short
dns010.d.register.com.
dns071.a.register.com.
dns024.c.register.com.
dns150.b.register.com.
Now look up the mail servers for the same domain:
dig karkomaonline.com -t mx
...
;; ANSWER SECTION:
karkomaonline.com. 86400 IN MX 0 mailhost.karkomaonline.com.
...
From the output of the first example you can see that by default dig queried my internal DNS server (configured in /etc/resolv.conf):
...
;; SERVER: 192.168.1.9#53(192.168.1.9)
...
You can change this behaviour by instructing dig to query a specific name server:
dig @dns010.d.register.com karkomaonline.com -t mx
...
;; ANSWER SECTION:
karkomaonline.com. 86400 IN MX 0 mailhost.karkomaonline.com.
;; ADDITIONAL SECTION:
mailhost.karkomaonline.com. 86400 IN A 94.75.208.171
;; Query time: 181 msec
;; SERVER: 216.21.236.10#53(216.21.236.10)
...
Note that the queried server now is 216.21.236.10.
More info::
If you want to mount an ISO image as a filesystem, simply proceed as follows:
mkdir /mnt/iso0
mount -o loop -t iso9660 /tmp/debian-40r6-amd64-netinst.iso /mnt/iso0
saidar is a top like tool. It provides a curses based interface for viewing system statistics such as network I/O, disk I/O, CPU, memory and more. The core of the functionality is provided by the libstatgrab library:
libstatgrab is a library that provides cross platform access to statistics about the system on which it's run. It's written in C and presents a selection of useful interfaces which can be used to access key system statistics. The current list of statistics includes CPU usage, memory utilisation, disk usage, process counts, network traffic, disk I/O, and more.
On a Debian system install the package as usual:
apt-get install saidar
and then run:
saidar
In some situations it is very useful to have the possibility to access the GRUB boot menu from a serial line. For example you could remotely reboot your machine with the new kernel you just compiled.
In my case I have a couple of remote machines linked together by a serial cable. I can log into machine A via ssh and get the Grub menu of machine B through minicom. Thus I can boot whatever OS/kernel I want as if I were in front of the machine. Kind of KVM IP for the rest of us.
Simply add this to Grub’s menu.lst:
serial –unit=0 –speed=9600 –word=8 –parity=no –stop=1
terminal serial
Say that you have a table called myTable with several rows and a column called URL that contains the IP address of a log server. Now imagine that you want to change the value of URL so IP address is substituted by the server name. One way to do that is as follows:
use dbname
update myTbl set URL=replace(URL,’172.16.1.10′,’logserver’);
OpenSSH provides a per-user configuration file usually located in ~/.ssh/config. This file can help ease your life as Sysadmin. Let’s say that you frequently connect to a server in this way:
ssh admin@boring-servername.boring-domain.com
With OpenSSH there is an easy way to do the job. Edit or create a config file:
vi ~/.ssh/config
and then add the following:
Host servername
User admin
HostName boring-servername.boring-domain.com
Where Host is the alias for the remote server you want to connect to, HostName is the full name of the remote server and User is the login name.
References:
Perl, you know perl, is not just a jewel for scripting, it ’s also a potent onliner.
The magic trick is the diamond:
perl -e ‘while (){print}’ file1
says perl “keep on as long as you read something in the standard in”, in the case of the example above, “print the line” … and each line goes in the memory but not the whole file: you have a powerful stream editor.
The ” -e” switch says to perl that what follows in the command line between the single quotations is a script and not a script file name.
But you can have it quicklier :
perl -ane ‘print’ file1
The switches “-ane” do the “while stuff” for you. It says “do a while () loop” (-n) “and split each record in the @F array” (-a), I haven’t used the array yet.
Perl has a difficulty : you can implicit everything. Some guys abuse of it in scripting, like spirits, but it’s good for an onliner.
This line will print file1. Great (in fact implicit in “print $_” ; $_ is the variable where perl puts what you do not explicit). Printing is great but let do some awkish things :
perl -ane ‘/$m[aiy]/ && print $_’
That will print the lines that contain $ma, $mi or $my, (have a look at the article from karkoma about sed), patterns in perl are like sed’s ones but larger. Take a look at the tutorial of perl for pattern or type “perldoc perlreftut” if you have installed perldoc.
Well, just let do some sedish thinks :
perl -ane ’s/
]*)>//; s/
/
/;print’ file1.html
replaces the paragraph in html( by newline () but keeps the options of the paragraph ($1, first match, here the parenthesis are not optional) in an html comment.
perl -F”:” -ane ‘/pascal/ && print $F[2]‘ /etc/passwd
will print the UID of user pascal (third field), the field separator is “:” (-F$-1òý:òý)
perl -ane ‘/$m[aiy][^ s]*/ && print “line : $. variable : $&n”‘
will print the number of line ($.) where the variables that begin with “$ma”, “$mi” o “$my” and the variables that have matched the description ($&)
bad news, you received this bad MS file with carriage return (r) and newline and you want only the newline :
perl -pi.old -ane ’s/rn$/n/;print;’ file1
and I obtain directly a file1 without carriage return and I have a backup of the original in file1.old (-pi.old)
you can have a look to a quick look at some useful perl onliners.