Find out whether a filesystem check is scheduled for the next boot.

To find out whether a filesystem check is scheduled for the next boot. Use this command: “dumpe2fs -h /dev/disk”.
Fsck will run if mount count is equal or greater than maximum mount count, or if “next check after” is passed.

Continue reading “Find out whether a filesystem check is scheduled for the next boot.”

Extract specific file(s) from tar.gz

To list the contents of an archive called tarball.tar.gz use this command:

tar -tzf tarball.tar.gz

example:
tarball/file1.txt
tarball/.bash_logout
tarball/file2.txt
tarball/bash.txt
tarball/.bash_history

Then you extract whatever you wish using this command:

tar -zxvf tarball.tar.gz tarball/bash.txt

example:
find . -type f
./tarball/bash.txt
./tarball.tar.gz

To extract a few files use this:

tar -zxvf tarball.tar.gz tarball/bash.txt tarball/file1.txt

find . -type f
./tarball/bash.txt
./tarball/file1.txt
./tarball.tar.gz

comm – compare two sorted files line by line.

Usage: comm [OPTION]… FILE1 FILE2
Compare sorted files FILE1 and FILE2 line by line.

With no options, produce three-column output. Column one contains
lines unique to FILE1, column two contains lines unique to FILE2,
and column three contains lines common to both files.

-1 suppress column 1 (lines unique to FILE1)
-2 suppress column 2 (lines unique to FILE2)
-3 suppress column 3 (lines that appear in both files)

–check-order check that the input is correctly sorted, even
if all input lines are pairable
–nocheck-order do not check that the input is correctly sorted
–output-delimiter=STR separate columns with STR
–help display this help and exit
–version output version information and exit

Note, comparisons honor the rules specified by ‘LC_COLLATE’.

Examples:
comm -12 file1 file2 Print only lines present in both file1 and file2.
comm -3 file1 file2 Print lines in file1 not in file2, and vice versa.

GNU coreutils online help:
Full documentation at:
or available locally via: info ‘(coreutils) comm invocation’

SSL – Check whether a private key matches a certificate or whether a certificate matches a certificate signing request (CSR).

Check whether a private key matches a certificate or whether a certificate matches a certificate signing request (CSR). If you are receiving an error that the private doesn’t match the certificate or that a certificate that you installed to a site is not trusted, try one of these commands. Check an MD5 hash of the public key to ensure that it matches with what is in a CSR or private key.

root# openssl x509 -noout -modulus -in certificate.crt | openssl md5
root# openssl rsa -noout -modulus -in privatekey.key | openssl md5
root# openssl req -noout -modulus -in csr.csr | openssl md5

For example:
root# openssl req -noout -modulus -in just4testcert_req.csr | openssl md5
(stdin)= 61c59f9a9ddddc032e56fe2e46a91409
root# openssl rsa -noout -modulus -in just4test_server.key | openssl md5
(stdin)= 61c59f9a9ddddc032e56fe2e46a91409

Clear Winbind cache

Clear all Winbind caches and flush Net cache, always take a backup before deleting 😉

Stop the Winbind service and Samba service (if you have it):

root# service winbind stop
root# service smb stop

Clear the Samba Net cache:

root# net cache flush

Delete the Winbind caches:

root# rm –f /var/lib/samba/*.tdb
root# rm –f /var/lib/samba/group_mapping.ldb

Start the Samba (if you have it) and then Winbind services

root# service smb start
root# service winbind start

lsof – list open files.

lsof – list open files for more information, please see the man page 😉

List process running on a port
root# lsof -i :port_number

Lists IPv4, use 6 for IPv6
root# lsof -i 4

Lists open files for TCP port ranges 1-1024
root# lsof -i :1-1024

Lists by pid
root# lsof -p PID

List files opened by a specific user
root# lsof -u username

Kill all activity for a particular user
root# killall -9 `lsof -t -u username`

List all network connections
root# lsof -i

List the opened files in a directory
root# lsof +D path_of_the_directory

List the opened files based on process names
root# lsof -c process_name

Rsyslogd the traditional File Format.

Add the following $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat to /etc/rsyslogd.conf to have a traditional file format like this:

Jan 12 15:51:07 sles29 dovecot: imap-login: Aborted login (no auth attempts in 0 secs): user=<>, rip=172.16.12.151, lip=172.16.60.15, session=
Jan 12 15:51:14 sles29 postfix/smtpd[9226]: connect from unknown[172.16.12.151]
Jan 12 15:51:14 sles29 postfix/smtpd[9226]: disconnect from unknown[172.16.12.151]
Jan 12 15:51:17 sles29 postfix/postfix-script[10446]: stopping the Postfix mail system
Jan 12 15:51:17 sles29 postfix/master[9120]: terminating on signal 15

instead of this:
2016-01-12T15:50:14.273797+00:00 sles29 postfix/smtpd[9226]: connect from unknown[172.16.12.151]
2016-01-12T15:50:14.274207+00:00 sles29 postfix/anvil[9231]: statistics: max connection rate 1/60s for (smtp:172.16.12.151) at Jan 12 15:40:14
2016-01-12T15:50:14.274534+00:00 sles29 postfix/anvil[9231]: statistics: max connection count 1 for (smtp:172.16.12.151) at Jan 12 15:40:14
2016-01-12T15:50:14.274781+00:00 sles29 postfix/anvil[9231]: statistics: max cache size 2 at Jan 12 15:41:53
2016-01-12T15:50:14.281123+00:00 sles29 postfix/smtpd[9226]: disconnect from unknown[172.16.12.151]

Debian packages – list and install on another server.

To list all currently installed packages, type “dpkg –get-selections”. You can save this data to a file by running “dpkg --get-selections > ~/packages.txt“.
And then place this file on another system and install the listed packages by running “cat packages.txt > sudo dpkg --set-selections && sudo apt-get dselect-upgrade“.
Also, the list of packages can be loaded for installation by running “dpkg --clear-selections && sudo dpkg --set-selections < packages.txt".
This could be used also for recovery. This trick is helpful when a system must be reinstalled, then all of the same packages can be installed all at once.
Sometimes, the output of "dpkg --get-selections" may list packages marked to be uninstalled or some other status. If so happens, use the following "dpkg --get-selections | grep -w install$ > ~/packages.txt". I mean, "| grep -w install$"

Smokeping on Debian/Ubuntu.

To install smokeping:

root# apt-get install smokeping

Link in the smokeping apache config:

root# cd /etc/apache2/conf-available
root# ln -s ../../smokeping/apache2.conf smokeping.conf

Enable the config and mod_cgi:

root# a2enconf smokeping
root# a2enmod cgid

Reload Apache:

root# /etc/init.d/./apache2 reload

Configuration files can be found here: /etc/smokeping/config.d/

root# ls -la /etc/smokeping/config.d/
total 64
drwxr-xr-x 2 root root 4096 Nov 23 09:06 .
drwxr-xr-x 3 root root 4096 Nov 19 13:07 ..
-rw-r–r– 1 root root 165 Nov 19 12:41 Alerts
-rw-r–r– 1 root root 237 Jul 8 2014 Database
-rw-r–r– 1 root root 509 Nov 19 09:31 General
-rw-r–r– 1 root root 225 Jul 8 2014 pathnames
-rw-r–r– 1 root root 876 Jul 8 2014 Presentation
-rw-r–r– 1 root root 50 Jul 8 2014 Probes
-rw-r–r– 1 root root 147 Jul 8 2014 Slaves
-rw-r–r– 1 root root 9025 Nov 23 09:06 Targets
-rw-r–r– 1 root root 9039 Nov 23 09:00 Targets_okay
-rw-r–r– 1 root root 380 Jul 8 2014 Targets_orig
root#