Yep. I forget things. I love to learn new things, but sometimes, I can't quite remember how I did them. Feel free to use this repository as I do: A vault of things I want to remember...
Thursday, December 15, 2011
Wednesday, December 14, 2011
Shell: convert UPPER case to lower case
Hate CAPITOL LETTERS!? Yea, me too. If some noob sends you an all capitol letter based server-name feel free to:
1) hit them
2) convert the letters to LOWER CASE.
echo $word| tr [:upper:] [:lower:]
This will use tr (translate) to move the characters from UPPER to lower case.
1) hit them
2) convert the letters to LOWER CASE.
echo $word| tr [:upper:] [:lower:]
This will use tr (translate) to move the characters from UPPER to lower case.
Monday, December 5, 2011
Get one word (or phrase) only from a set of text or file
So you want to get some text from a file. Easy, use grep. What; you want more than that? Oh, you want ONLY the word (or phrase) from that file, not the entire line! Ahhh!
It took me a few tries, but I combined grep and sed to give me the line I wanted, then then only the word I wanted.
In this case I was searching spam emails I have gotten for the senders email address.
grep -i "From: " *| sed -e 's/^.*<\(.*\)>,*/\1/'
The line from the grep looks like:
3 0735.eml:From: "Fraud Prevention" <douchbag@spamsucks.com>
Then the sed line pulls out the email between the < >
It took me a few tries, but I combined grep and sed to give me the line I wanted, then then only the word I wanted.
In this case I was searching spam emails I have gotten for the senders email address.
grep -i "From: " *| sed -e 's/^.*<\(.*\)>,*/\1/'
The line from the grep looks like:
3 0735.eml:From: "Fraud Prevention" <douchbag@spamsucks.com>
Then the sed line pulls out the email between the < >
Thursday, October 27, 2011
Save a file edited in vim without the needed permissions
:w !sudo tee %
Have you ever been editing a file in vi or vim and found out that you cannot save it due to permissions? Yea, me too. Ugh! The shortcut above utilizes your sudo permissions to hand off the write to tee so that it can be saved out of vi or vim.
Rejoice! Of course this requires that you have at least sudo permissions to edit the file. Sorry hackers!
Wednesday, September 7, 2011
Force an unmount with umount -l
Force (a clean) umount:
umount -l /path/to/mount
# the -l (lower case L) option is lazy unmount
From the man page for (-l):
Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup all ref-erences to the filesystem as soon as it is not busy anymore.
(Requires kernel 2.4.11 or later.)
umount -l /path/to/mount
# the -l (lower case L) option is lazy unmount
From the man page for (-l):
Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup all ref-erences to the filesystem as soon as it is not busy anymore.
(Requires kernel 2.4.11 or later.)
Thursday, September 1, 2011
LDAP search AD from linux: ldapsearch
So you have linux systems in a network that utilize LDAP via windows Active directory (AD), eh? Yea, cool stuff. The project came up as to how to monitor them, because the windows folks forget that a down domain controller (DC) means a down network. I digress...
Anywho, I was handed the project to monitor and alarm our AD (LDAP) domain controllers. I decided to write a nagios shell plugin, and the main query tool is the linux command: ldapsearch
# Explanation: (of course the man page help too... :)
-x = simple search
-D = who to use for authentication
-W = ask for password (-w "password" otherwise)
-b = where to begin search
-h = domain controller address (-H ldaps://<address> otherwise)
"(sn=XYZ)" = search for sn (sir_name=XYZ) [known as filter]
last part with cn, displayName, etc... = what to return
Good luck!
Anywho, I was handed the project to monitor and alarm our AD (LDAP) domain controllers. I decided to write a nagios shell plugin, and the main query tool is the linux command: ldapsearch
# Example search
ldapsearch -x -D "user_name@example.com" -W -b "DC=example,DC=com" -h example.com "(sn=last_name)" cn displayName mail sn
# RESULTS:
# user_name, (other domain info returned here)
dn: CN=user_name,OU=one,OU=two,OU=three,DC=example,DC=com
cn: user_name
sn: last_name
displayName: Last, Name, M.
mail: mail_user_name@example.com
ldapsearch -x -D "user_name@example.com" -W -b "DC=example,DC=com" -h example.com "(sn=last_name)" cn displayName mail sn
# RESULTS:
# user_name, (other domain info returned here)
dn: CN=user_name,OU=one,OU=two,OU=three,DC=example,DC=com
cn: user_name
sn: last_name
displayName: Last, Name, M.
mail: mail_user_name@example.com
-x = simple search
-D = who to use for authentication
-W = ask for password (-w "password" otherwise)
-b = where to begin search
-h = domain controller address (-H ldaps://<address> otherwise)
"(sn=XYZ)" = search for sn (sir_name=XYZ) [known as filter]
last part with cn, displayName, etc... = what to return
Good luck!
Subscribe to:
Posts (Atom)