What to do when you want info@amz.com to go to sbp@amz.com? Well, you could look in the OS X Mail Service documentation or you could follow these directions:
sudo emacs /etc/aliases
add your alias like so:
fakename: realuser, realuser, realuser
save the file, then:
sudo postalias /etc/aliases
sudo newaliases
sudo postfix reload
and then send a test email to each alias you've created. Neat!
Apache. Would be nice if it just ran for 36 months between reboots, but once in a blue moon you have to manually stop and start it. When those days come, here's what you do:
/usr/local/sbin/apachectl restart
apachectl stop
apachectl start
Date is a handy command. Typed by itself it spits out the current date and time.
date
Fri Nov 6 16:20:00 PST 1998If you are the root user, Date can also be used to set the date and time, like so:
date 9811061420sets the date to November 11, 1998 4:20pm
Disk Use (du) is how you find out how much space you've used on your hard drive.
du -ax ~amzdev | sort -nr | less
provides a sorted list of the biggest files so you can clean out your directories. Replace ~amzdev with the directory of your choice.
Need to know how much space files and directories are using? Here's your command:
du -h -s pathname
Need to find out what DNS servers you're using? Here's a command line gizmo that will give that to you. Also works in the terminal of Mac OS X!
cat /etc/resolv.conf
DNS is tricky, but hopefully this is enough of a clue that we can make simple edits on our servers.
- Be root
- cd /etc/namedb
- Each domain name needs a zone file. Feel free to copy an existing one. Replace the name in the zone file with the new domain name you're controlling with that file.
- cp namedb.conf namedb.conf.bak (now if you goof it up, you can go back to the working config)
- emacs namedb.conf (you do know emacs, right?)
- Put in an entry like this for your new domain name
zone "lillalavender.com" {
type master;
file "lillalavender.com-zone";
};
- Save namedb.conf, then restart the name service like this: ndc restart
- That should do it. You can check like this: nslookup foobar.com
If you get an IP address back, then you've set it up correctly!
Holy cow! What's htaccess? It's what lets you set passwords on web directories in UNIX. Too complicated to explain here, check out the tutorial.
Let's say you've walked away from a computer somewhere and left it running a shell session to your favorate host but now any random loser can type on it! Oh No! Wait, just try this:
kill `ps auxwww | grep sbp | awk '{print $2}'`
Locate is a handy command. It's like the find command in Mac or Windos95. It's used like this:
locate filenameFor the filename you can use the entire filename, or just a piece, like so:
locate nts.txtWould search and produce a list of files that would include "clients.txt".
Symlinks are a like "aliases" to files on the Macintosh and "shortcuts" in Windoze. "Symlink" is actually short for "symbolic link" and it's handy any time you might want to have it appear like a single file is in several places.
ln -s /path/to/original/file /path/to/symlinkLet's say you wanted to use Myke's .signature file, but he changes it often so if you just copied it, it would never be up to date. You can create a link to his file like so:
ln -s ~myke/.signature ~sbp/.signatureYou can name your links anything convenient. Naturally, with a .signature it has to be named .signature to work.
Start by dumping the data out of the original server
shell> mysqldump --user=root -p --opt db_name > backup-file.sql ; --add-drop-tableCopy the backup-file.sql to the new server and reconstitute the DB like so:
mysql db_name < backup-file.sql
This is complicated, here's the basic commands:
shell> mysql --user=root mysql
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> ON db_name.*
-> TO 'user_name'@'hostname'
-> IDENTIFIED BY 'the_password';This gives "user_name" all the permissions you could want on database "db_name" from "hostname". If you wanted to give "user_name" permissions from any host you can do this instead:
-> TO 'user_name'@'%'or, if you wanted to give permissions to just users from amz.com:
-> TO 'user_name'@'%.amz.com'
Any time you mess with the user accounts and permissions, you need to do this:
mysql> FLUSH PRIVILEGES;To force MySQL to make them active.
More documentation on this can be found here: http://dev.mysql.com/doc/mysql/en/adding-users.html
MySQL is a handy open source database tool that we're using to take over the world. Here's how to start and stop it on cheese.amz.com. Step 1: become root. Then:
killall mysqldWait a minute or two. It may take a moment to shut down. To check that it's all turned off, do this:
ps -auxwww | grep mysqlIf you get nothing other than the grep process, it's shut down. Now, start it back up!
/usr/local/etc/rc.d/mysql.shor if that doesn't work, try this:
/usr/local/share/mysql/mysql.server start
That should do it. Another kewl MySQL command that may come in handy: mysqladmin. Yet another knockout klew is that you can use -h 127.0.0.1 with mysqladmin to make sure it knows it's talking to the computer you're typing on.
There is a rename command in some UNIX systems, but in case you don't have it this short script will rename a directory of files for you:
for f in *.html; do mv $f `basename $f .html`.php; doneCut and paste it to the command line. The above incarnation will rename all files from .html to .php.
for f in *; do mv $f `basename $f`.jpg; doneWill add .jpg to every file in the directory.
This is something of an antique way to attach files to emails. It's called "uuencoding" which stands for unix-to-unix file encoding (Myke may be able to correct my memory on that one). There are utilities for decoding these files for your favorate desktop computer (MacLink Plus for Macintosh), here is the command-line way:
Save the email to a file. Edit out any text that isn't part of the UUencoding - that is, everything above the "begin" line and after the "end" line. Make sure the filename doesn't have any spaces. The filename is specified in the "begin" line like so - "begin 600 website - HR portion only.doc". Change that line to read - "begin 600 HR_copy.doc". Now on the command line type:
uudecode bletchfileIn a second you'll discover that it created a file in the same directory with the name you put in the begin line!
sendmail -q -vSends queue'd email if you're logged on as root. Use this if our network connection's been down and there's stuff waiting in the queue you'd like to go out right away.
SpamAssassin's the thing for shooting down spam as it arrives to your UNIX mailbox. Here's how to set it up on your account on cheese.amz.com.
First of all, you need to use procmail. Y'all do that already, right?
Make your .forward look like this:
|/usr/local/bin/procmail
Ok, so you can run this as an individual perl script for each incoming mail, or you can run a daemon. I went ahead and set up the daemon, and added a line to rc.local to get it to run on reboot. The daemon is /usr/local/scripts/spamd. The client is /usr/local/scripts/spamc.
Here's my .procmailrc:
SHELL=/bin/sh LOGFILE=/home/noah/.procmail/log
:0fw | /usr/local/scripts/spamc -f
#:0: #* ^X-Spam-Status: Yes #/home/noah/mail/spamassassin-caughtNote that this saves suspected spam messages to a mail folder called "spamassassin-caught". If you'd prefer to have it just throw the nasty stuff away, make that last line look like this:
#:0: #* ^X-Spam-Status: Yes #/dev/nullSpam Assassin can also be taught to recognize spam from non-spam by example. Save spam to a folder, become root, and run this script like so:
/usr/local/scripts/sa-learn --spam --mbox /home/noah/mail/spamAfter "-mbx" put in the path to the mail folder where the spam in question is located. Go git 'em cowboy!
su - username
Change to a different user. Certain tasks can only be done by Root. Not everyone can "su" to root. Only those special people in group "Wheel".If you are sitting at Wallace and you want your graphic windows to show up in X windows, give the following command to tell your shell session where to send the window:
export DISPLAY=:0.0
compress files -
tar -cvf tarfile.tar file_or_directory
extract files -
tar -xvf tarfile.tar
compress files -
tar -cvzf tarfile.tar file_or_directory
extract files -
tar -xvzf tarfile.tar
This will work on Milk. In your home directory create a file named .forward. In it put a line that reads:
|/usr/local/bin/procmail
Create a file called .procmailrc, in it put this:
SHELL=/bin/sh
LOGFILE=/dev/null
:0 c
| /usr/local/bin/autoreply /home/USER_NAME_ON_MILK/autoreply.txt
Then, create a file called autoreply.txt that looks like this:
From: Joe User <spam@amz.com>
Subject: Out of Office
Precedence: bulk
This is the test autoreply, I am out of the office.
Thank you,
Craig Giffen
...and that should do it!
- Download mtr at ftp://ftp.bitwizard.nl/mtr
- expand the tar archive like so:
tar -xvzf foobar.tar.gz
- Inside the decompressed folder, open "config.h.in" inside your favorite text editor. Add the line
#define BIND_8_COMPAT 1- In terminal, cd to the decompressed folder, and type in the standard compilation commands:
./configure
make
sudo make install- mtr should now be found in /usr/local/sbin if that's not in your path you can run it like so:
/usr/local/sbin/mtr