Archive for Jr Admin

Slightly more advanced uses of find for finding files between two dates/times

I’ve used find commands before and talked about them on Unixsupport.com, however I recently needed to stack a few find commands and found it less then easy to search out support… so:

find . \( -ctime +1 -not -ctime +3 \) | xargs -I{} ls -l {}

find files, in the current directory, that were created more then 1 day ago, not, more then 3 days ago, then send them over to ls to show them to me

Comments

Simple Testing of SMTP with Telnet

SMTP is a pretty straightforward protocol, and thats why it is so simple for spammers to mess with, but it also makes it easy for us to test if its working.

Many times you want to verify your server before bringing it live in your MX record or even just test to make sure everything is good on your sendmail side.

Simple way of doing this is using telnet from the command line:

$ telnet your.mail.server.name.com 25

Trying your.mail.server.name.com…
Connected to your.mail.server.name.com.
Escape character is ‘^]’
220 your.mail.server.name.com ESMTP Sendmail 10.0.1/10.0.1; Mon, 13 Aug 2007 18:36:27 -0400 (EDT)

HELO your.doman.com
250 your.mail.server.name.com, nice to meet you!
MAIL FROM:you@your.domain.com
250 2.1.0 you@your.domain.com… Sender ok

RCPT TO:me@your.domain.com
250 me@your.domain.com… Recipient ok
DATA
354 Enter mail, end with “.” on a line by itself

Put your message here, and finish with a line that
only contains a period, so hit enter, then hit period, then hit enter, like below
.

250 2.0.0 l7DMerMV044784 Message accepted for delivery
QUIT

That should give you a good idea of what areas are having issues, so if you receive something like:
550 5.7.1 someone@someother.com… Relaying denied

you know that the mail server isn’t setup to receive messages for that user, or that the server is mis-configured for relaying.

Comments

Quick test of TCP between firewalls with Netcat

So sometimes I’m on a box and need to test if a port is cleared on a firewall.. i may not yet have apache installed but I want to test if port 80 is open, or I may want to act as a server to grab a request..

simple with Netcat.

nc -l -p 8080

will open a listen on port 8080 and after the first connect, exit and go back to shell… useful for testing

Comments

Quickly create files of a specific size for tests

Sometimes I’ve had to create files to test transfer speeds between points.. sure you could transfer that 650 meg iso image of freebsd, or you could create a “blank” file..

dd if=/dev/zero of=linux.ex2 bs=1024 count=131072

creates 128mb blank file

dd if=/dev/random of=linux.ex2 bs=1024 count=131072

creates 128mb file with random characters in it

for example.. play around with the count numbers in bytes and your set.

Comments

Simple overwriting of files in current working directory

When I do server configurations for large numbers of domain names, I like keeping files organized specifically by their domain name, and then I have a sample file that I build off of.

Often times I want to create new configuration files from an existing directory of all of those domain names (for example, if I needed zone records for each one)

for x in `ls`; do cat /directory1/filename >> /directory2/new/$x; done

what it does is for every line in ls (of the current directory) it outputs a file into /directory2/new/(every line in LS)

It’s a great timesaver… and can be used in a bunch of different ways

for x in `ls`; do touch $x; done
update every file in the directory to current time, great for organizing your config directories when you have a known working config

for x in `cat list`; do rm -rf $x; done
cat a file and delete each file in list

the list goes on…

Comments

find modified files within last 24 hours, minutes, etc

This is a simple one that I tend to forget when I need it most… finding files in a current directory that have been modified within the last 24 hours… while I realize my standard ls -lgat gives me a list of all files, it sucks when your doing a directory of thousands of files..

so in comes find :)
——
find -mtime x [where x is how many days]
or
find -mmin x [where x is how many minutes]
——
Lets see this in action on my home directory.
$ find -mmin 1
[ no files found modified within 1 minute ]
$ find -mtime 5
[ no files found modified within 5 days ]
lets create one

$ touch test
$ find -mmin 1
.
./test
Bingo.
$

This can be expanded a bit, modified files are different then the last accessed, etc.

Just a useful one.

Comments

« Previous entries ·