base64 encoding decoding with openssl
Thu, 08/30/2012 - 16:28 — sandipBase64 encoding with openssl:
echo -n 'encode this with base64' | openssl enc -base64
ZW5jb2RlIHRoaXMgd2l0aCBiYXNl NjQ=
Base64 decoding with openssl:
echo 'ZW5jb2RlIHRoaXMgd2l0aCBi YXNlNjQ=' | openssl enc -base64 -d
encode this with base64
- sandip's blog
- Login or register to post comments
- Read more
Handling filenames with spaces, carriage returns or other control characters
Mon, 08/27/2012 - 23:42 — sandipfind -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.
- sandip's blog
- Login or register to post comments
- Read more
Get public IP Address
Mon, 08/27/2012 - 21:01 — sandipGet 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
- sandip's blog
- Login or register to post comments
- Read more
host map: lookup (domain): deferred
Tue, 08/21/2012 - 09:17 — sandipThis 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
Fri, 06/22/2012 - 08:04 — sandipThis 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
- sandip's blog
- Login or register to post comments
- Read more
vBulletin login quota
Thu, 06/07/2012 - 10:20 — sandipIf 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;
- sandip's blog
- Login or register to post comments
- Read more
Extract IP address
Tue, 05/15/2012 - 15:22 — sandipOne 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
Fri, 04/13/2012 - 15:01 — sandipThe 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.
- sandip's blog
- Login or register to post comments
- Read more
group writable web folders with setgid and ACL
Tue, 04/03/2012 - 10:18 — sandipOften 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 & nbsp; & nbsp; 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:developer s: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
- sandip's blog
- Login or register to post comments
- Read more
Getting the most out of Grub
Tue, 04/03/2012 - 07:40 — sandipThe 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.