Enable the serial console for custom Linux VM image on Azure

To enable the serial console for your custom Linux VM image, enable console access in the file /etc/inittab to run a terminal on ttyS0.

For example: S0:12345:respawn:/sbin/agetty -L 115200 console vt102.

You may also need to spawn a getty on ttyS0 and this can be done with systemctl start serial-getty@ttyS0.service.

How to configure a Linux service to start automatically after a crash.

Under the [Service] section of let’s say Postfix in the file /usr/lib/systemd/system/postfix.service add the following 2 lines:

Restart=always
RestarSec=5

Then you need to reload the daemon configurations to ensure systemd is aware of this change by doing:

systemctl daemon-reload
systemctl restart postfix.service

server:~ # ps aux | grep postfix
root     24446  0.0  0.0  34180  3216 ?        Ss   12:53   0:00 /usr/lib/postfix/bin//master -w
postfix  24447  0.0  0.1  35820  3996 ?        S    12:53   0:00 pickup -l -t fifo -u
postfix  24448  0.0  0.1  36204  5732 ?        S    12:53   0:00 qmgr -l -t fifo -u
root     24523  0.0  0.0   9288  1636 pts/0    S+   13:08   0:00 grep --color=auto postfix
server:~ # kill -9 24446
server:~ # ps aux | grep postfix
root     24549  0.0  0.0   9288  1636 pts/0    S+   13:08   0:00 grep --color=auto postfix
server:~ # ps aux | grep postfix
root     24644  0.0  0.0  34180  3216 ?        Ss   13:08   0:00 /usr/lib/postfix/bin//master -w
postfix  24645  0.0  0.1  35820  3992 ?        S    13:08   0:00 pickup -l -t fifo -u
postfix  24646  0.0  0.1  36204  5732 ?        S    13:08   0:00 qmgr -l -t fifo -u
root     24662  0.0  0.0   9288  1632 pts/0    S+   13:08   0:00 grep --color=auto postfix
server:~ #



Convert .pem into .key

Convert .pem into .key

root# openssl rsa -in privkey.pem -out private.key

.pem – Defined in RFCs 1421 through 1424, this is a container format that may include just the public certificate (such as with Apache installs, and CA certificate files /etc/ssl/certs), or may include an entire certificate chain including public key, private key, and root certificates. Confusingly, it may also encode a CSR (e.g. as used here) as the PKCS10 format can be translated into PEM. The name is from Privacy Enhanced Mail (PEM), a failed method for secure email but the container format it used lives on, and is a base64 translation of the x509 ASN.1 keys.


.key – This is a PEM formatted file containing just the private-key of a specific certificate and is merely a conventional name and not a standardized one. In Apache installs, this frequently resides in /etc/ssl/private. The rights on these files are very important, and some programs will refuse to load these certificates if they are set wrong.

Character Names

Character Name Character

Accent `
Ampersand &
Angle Brackets < >
Apostrophe ’
Asterisk *
At Symbol @
Backslash
Braces [ ]
Brackets { }
Circumflex ^
Colon :
Comma ,
Dollar Sign $
Equal Sign =
Exclamation Point !
Hyphen –
Number Sign #
Parentheses ( )
Percent Symbol %
Period .
Pipe |
Plus Sign +
Question Mark ?
Quotation Mark “
Semicolon :
Forward Slash /
Tilde ~
Underscore _
Uppercase Letters A-Z
Lowercase Letters a-z
Numerals 0-9

Enable or disable query logging in Bind.

To enable query logging use:

root# rndc querylog on

To disable query logging use:

root# rndc querylog off

Query logging can also be enabled by explicitly directing the queries category to a channel in the logging section of named.conf or by specifying “querylog yes;” in the options section of “named.conf”.
By default query logging will go to /var/log/messages to avoid this situation, create the logging channels:

logging {
channel default_file {
file "/var/log/named.log" size 100m;
severity dynamic;
print-time yes;
print-severity yes;
print-category yes;
};
channel queries_file {
file "/var/log/queries.log" size 100m;
severity dynamic;
print-time yes;
print-severity yes;
print-category yes;
};
category queries { queries_file; };
category default { default_file; };
};

How to convert bytes to KB and MB in Excel?

In Excel, to convert “bytes” from a cell D2 to KB/MB in a cell C2, insert the following to a cell C2:

=IF(D2>=1048576,D2/1000000&" MB",IF(AND(D2<1048576,D2>1024),D2/1000&" KB",D2&" BYTES"))

And then copy the formula down by dragging the bottom right-hand corner of the cell with the formula to the end of your KB/MB info already entered.

Resizing images on Linux – ImageMagick convert command

With the resolution of today’s digital cameras it is often necessary to resize the files to make them smaller. You may want to reduce the file size before publishing them on the web, or sending in an email. There is however the convert command which is part of the ImageMagick suite. If you are running Linux then you most likely have that installed already, just man convert for more information. The most basic way to use convert is to give a file at a time on the command line:

convert -resize 50% original.jpg newsize.jpg

Alternatively you could replace the percentage with the actual size such as 640×480

convert -resize 640x480 original.jpg newsize.jpg

Where this really comes into it’s own is when you have a directory full of images that you want to convert. This can be used by using the xargs and find commands in conjunction with convert.

find . -iname "*.jpg" | xargs -l -i convert -resize 640x480 {} ../small/{}