Archive for Linux

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

Nagios exec logging

Nagios can be a pain in the butt to troubleshoot because finding out what it is passing to it’s plugins isn’t easy to log.

A friend says that this works, haven’t tried it yet, but it seems logical.

strace -s 4096 /usr/local/nagios/bin/nagios -c /usr/local/nagios/etc/nagios.cfg 2>&1 | vim -

syntax on
set filetype=strace

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

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

Setting up User Quotas on Rehat

First there was the machine. And it was good. Then there were users. And disk space beacame scarce. Inevitably when admining a box with lots of users you’re going to run in to disk usage issues. You can tackle this before it becomes a problem by setting up disk space quotas for each user (or for groups but I’ll explain that later)

So the first thing you gotta do is enable quotas on the partition that your users reside on. To do this we edit fstab. In this example we’re going to set up quotas for users in /home. Append usrquotas to the defaults field in your fstab.

Change

/dev/hda5 /home ext3 defaults 1 1

To

/dev/hda5 /home ext3 defaults,usrquota 1 1

Now give it the old :wq!.

Since we’re edited fstab we need to remount the affected directory.

mount -o remount,rw /home

Okay, time for the nitty gritty. You need to set up the reference files quotas will need to run. Run:

quotacheck -C /home

This will create .aquota.user and .aquota.group which you won’t really touch.

So let’s set up a quota for user badmonkey. Run:

edquota badmonkey

You’ll enter vi file that looks like this.

Disk quotas for user badmonkey (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/hda5 112 0 0 19 0 0

Presently badmonkey is using 112K and has 19 files. You can set up quotas by 1K blocks or by inodes or both. The number under soft is the limit they can hit before recieving a warning. The number under hard is what they can hit before the system stops them from creating any new files.

Let’s say we want a hard limit of 512M and 800 files. We’ll make the soft limit 3/4’s of the hard limit. We’ll edit the file so it looks like this:

Disk quotas for user badmonkey (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/hda5 112 393216 524288 19 600 800

Do a :wq!. Now all that’s left is to turn quotas on.

quotaon /home.

You are done! badmonkey can no longer be such a badmonkey w/o dealing wiht the consequences. Bear in mind when you add a new user you’ll want to run quotacheck -C /home again (Which will require you to turn quotas off)

You can apply the same thing to groups. Howver you’ll also want to add grpquota to /etc/fstab.

Comments

« Previous entries ·