Quick Tips
TIP: Figuring out which RPM’s contain which files
by daven on Feb.18, 2009, under General System Administration, Quick Tips
If you ever need to know what files an RPM will install or what RPM’s “own” a file on your system then the rpm command has a few switches that can help you out.
If you want to know which file’s an installed RPM’s owns:
rpm -ql
If you have an RPM file and want to know what file’s it will create or modify before you install it:
rpm -qpl
And finally if you have a file or directory and you want to know which RPM installed it:
rpm -qf
TIP: force sudo to forget your password
by daven on Jan.26, 2009, under General System Administration, Quick Tips
Very rarely you need to force sudo to forget your cached password or token in super secret decoder ring lingo. All you need is one little flag an you are ready to
% sudo -k
See simple
TIP: search and replace, in place, across multiple files
by daven on Jan.20, 2009, under Automation, General System Administration, Quick Tips
Ever have that need to change one little thing in a bunch of files? You know after you accidentally misspelled your Boss’s name as “Marvin Blowhard” on every page of the Company website.
Now you could open up each file in vi and find every reference to Mr. Blowhard to Joe Smith, even using search & replace
s/Marvin Blowhard/Joe Smith/ inside vi get’s kind of tedious after a while. That joke doesn’t seem so funny now, does it?
Now consider a little BASH and sed foo
for i in `ls *.html`; do sed "s:Marvin Blowhard:Joe Smith:g" $i >temp;mv temp $i; done
All nice and done so you can get back to planning your next BOFH moment, like sending him in the into the server room with a flash light to look for breaks in the fiber runs.
TIP: X forwarding after su’ing to another user
by daven on Oct.19, 2008, under General System Administration, Quick Tips
It is a fairly common occurrence now days for security purposes to disable remote login access for “role accounts” like Oracle or Mysql. This restricts you to logging as a normal user then using the su command to become the role users. It works great in almost every circumstance but what if you need access to a remote X display while su’ed to the role account? Just trying to run the X program as normal will give you an error.
So what do you do? Why you find the Magic Cookie!
Before doing su to the become the new user do
$ xauth list
You should get back a result that looks something like this
hostname.domainname.com:11 MIT-MAGIC-COOKIE-14d22408a71a55b41ccd1657d7923ae
Now that you have your Magic Cookie don’t forget to stock up on the munchies.
su to the new user and tell it what the Magic Cookie is so it can communicate with the Xserver.
su - someuser
password: *******
xauth add MIT-MAGIC-COOKIE-14d22408a71a55b41ccd1657d7923ae
Then export X programs as normal
Vacuuming your Mail.app
by daven on Mar.11, 2008, under Quick Tips, links
Want to speed up and improve the performance of Mail.app on your Mac? Just Vacuum it up and watch it fly
http://gracefulflavor.net/2007/03/16/simple-trick-speeds-up-mailapp-considerably/
TIP: Are we there yet part 2, using a watch dog
by daven on Jan.22, 2008, under Automation, General System Administration, Life in General, Quick Tips
As a follow up to the previous tip on getting notified. What do you do when you have an already running process that you would like have notify you when it completes?
So you kicked off this update that was only supposed to take a few minutes but now an hour later it is still running and you are tired of having to check up on it, wouldn’t it be nice if you could just get a nice little e-mail letting you know when its done. Well, this little one liner just might make your day, ok maybe your hour…
while [ $(ps auxww | grep -i SOMEPROCESS | grep -v grep > /dev/null; echo $?) -eq 0 ]; do echo -n “.”; sleep 5; done; echo `/bin/date` | mail -s “SOMEPROCESS has completed” me@example.com
This little ditty will print a “.” every 5 seconds while the process is running, then when it completes will shoot you a nice little e-mail with the time it completed in the body. Now just don’t forget to the processes in screen so they can keep running even if you get disconnected.
TIP: Are we there yet? Having a command notify you when its done
by daven on Jan.19, 2008, under Quick Tips
Sometimes you have a long running process and rather than check up on it periodically you would just rather have it notify you. From the command line this is really simple you can have it email you using the mail command.
% ps auxww ; echo "ps done" | mail -s "ps done" me@example.com
This will just email you “ps done”, now suppose you want the output of the command do
% ps auxww | mail -s "ps done" me@example.com
this will include the the output of the command in the body of the email message
% time ps auxww | mail -s "ps done" me@example.com
and finally include the bash command time before the command you will get the exact amount of time it took to run included at the bottom of the e-mail.
By piping to mail you can get a bit of piece of mind not needing to constantly check on you process and with the right options even get the output and the exact run time.
TIP: using Gmail to have mutliple unique e-mail addresses
by daven on Jan.02, 2008, under Quick Tips
Have you ever wanted to have a specific e-mail address for a site or maybe a throw away address so you can see if your credit car company is the one selling your e-mail address to spammers. Now you could use your own domain name and setup multiple e-mail addresses for each account and forward them on to a central mailbox for you to peruse. However, if you have a GMail account or if you don’t mind setting one up ( it is free after all ) you can use the usename+ trick.
To use this trick simply type your e-mail address and normal but in between your username and the @ enter in + followed by something descriptive. So for example if my gmail email address was notarealemailadddress@gmail.com and I wanted a unique e-mail address for cnn.com to you I could simply give them the e-mail address notarealemailaddress+cnn@gmail.com, GMail will then happily ignore the + and everything after it and deliver the e-mail to your inbox.
Have and if you find that someone was selling your address to spammers via this method make sure to let the world know what evil bastards they are.
TIP: using BASH for loops on the command line
by daven on Dec.07, 2007, under Automation, General System Administration, Quick Tips
Sometime you want to run a command or a series of commands in a loop to say shutdown all the nfs daemons via their init scripts. Now we could do them one at a time like:
$ /etc/init.d/nfs stop
Shutting down NFS mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Shutting down NFS quotas: [ OK ]
Shutting down NFS services: [ OK ]
$ /etc/init.d/nfslock stop
Stopping NFS locking: [ OK ]
Stopping NFS statd: [ OK ]
Or we could use a bash for loop with a little copy & paste
$ for i in /etc/init.d/nfs /etc/init.d/nfslock
> do
> $i stop
>done
Shutting down NFS mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Shutting down NFS quotas: [ OK ]
Shutting down NFS services: [ OK ]
Stopping NFS statd: [ OK ]
Or just completely automate it and get it down quick and easy
$ for i in `ls /etc/init.d/nf*`
> do
> $1 stop
>done
Shutting down NFS mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Shutting down NFS quotas: [ OK ]
Shutting down NFS services: [ OK ]
Stopping NFS statd: [ OK ]
It’s that simple and you saved your self a bunch of typing.
TIP: VIM — displaying line numbers
by daven on Nov.05, 2007, under General System Administration, Quick Tips
Sometimes in VIM it is useful to display line numbers, for example you want to be really accurate when deleting to line number X. Fortunaly, VIM includes a mode to display line numbers
To enable the display of lines numbers in command mode type:
:set number
To disable the display in command mode type:
:unset number
Now if you decide you would like line numbers to always be displayed simply add set number to your ~/.vimrc and you are all set