base64 encoding decoding with openssl

Base64 encoding with openssl:

echo -n 'encode this with base64' | openssl enc -base64
ZW5jb2RlIHRoaXMgd2l0aCBiYXNlNjQ=

Base64 decoding with openssl:

echo 'ZW5jb2RlIHRoaXMgd2l0aCBiYXNlNjQ=' | openssl enc -base64 -d
encode this with base64

Handling filenames with spaces, carriage returns or other control characters

find -print0 | while IFS= read -rd $'\0' filename ; do echo "[$filename]" ; done

-print0, prints the full file name on the standard output, followed by a null character instead of the newline character.

IFS, is the "Internal Field Separator" that is used for word splitting after expansion. Here, IFS is set to null string.

-r, specifies that backslash "\" does not act as an escape character.

-d, is the delimeter. Which in this case is the null character '\0'.

$'\0', the $ prefixed single quoted string decodes the backslash escape character. In this case a null character.

[], is simply there to print out the text, so you notice any spaces in the beginning and end of text.

Get public IP Address

Get current public IP via command line curl and wget.

With curl:

curl icanhazip.com
curl ifconfig.me

With wget:

wget -qO- icanhazip.com
wget -qO- ifconfig.me/ip

host map: lookup (domain): deferred

(via www.brandonhutchinson.com)

This Sendmail error--also seen as "Transient parse error -- message queued for future delivery" or "Name server: domain: host not found"--indicates that Sendmail encountered a problem with one of its DNS resource record lookups of the destination domain.

redirect stdout/stderr within bash script

This executes the date command via shell script and logs it to the specified file with current pid.

#!/bin/bash
LOG=$$.log
exec > $LOG 2>&1
date

vBulletin login quota

If you have typed in your admin password in vBulletin more than 5 times and get locked. Look at the vbulletin "strikes" table and truncate it to get back in and not have to wait for the 15 minutes lock out time.

TRUNCATE strikes;

Extract IP address

One liner with grep to extract the IP addresses from a file.

grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' /path/to/file

The "-o" option prints only the matched parts.

One liner with perl:

perl -ne 'print if s/.*((\d{1,3}\.){3}\d{1,3}).*/\1/' /path/to/file

Find size of ext3 Journal

The journal is located at inode:

# tune2fs -l /dev/sda1 | awk '/Journal inode/ {print $3}'

The size of journal in Bytes is:

# debugfs -R "stat <inodenumber>" /dev/sda1 | awk '/Size: /{print $6}'|head -1

Note: "<>" is necessary around the inode number.

group writable web folders with setgid and ACL

Often times, there is need for web-accessible folders to be set up so all web-developers have write access.

Along with setgid option, ACL can be used so anyone in the group "web-developers"
would have write privileges to anything under web-accessible document root.

So unless the acl privileges is revoked specifically, it would just continue to work.

To enable ACL, add "acl" option to /etc/fstab file for the corresponding partition and remount.

Edit /etc/fstab:

/dev/mapper/home /home           ext4    defaults,acl        0       2

Remount:

# mount -o remount /home

Here is the commands to be used for the setup:

# groupadd developers
# chgrp -R developers /path/to/docroot
# find /path/to/docroot -type d -exec chmod g+s {} \;
# find /path/to/docroot -type d -exec setfacl -m g:developers:rwx,d:g:developers:rwx {} \;
# find /path/to/docroot -type f -exec setfacl -m g:developers:rw {} \;

Now anyone needing write access can be put in the "developers" group.

# usermod -G developers {username}

If you need the webserver to have write access to certain folders, then chown the location to be owned by the webserver, instead of giving write permissions to all.

# chown apache /path/to/docroot/apache

Getting the most out of Grub

(via www.timburgess.net)

The grub bootloader is particularly useful, especially when upgrading and testing new kernels. I recently found a way to modifiy the default boot config to make it useful when you wish to remotely upgrade a kernel and boot into it once only without being at the console to change the default back.

Syndicate content
Comment