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

Troubleshooting qpage - a paging daemon

A common monitoring system, Nagios, uses qpage for sending alphanumeric pages via a modem.. yes it sound insane, but think about what happens to your monitoring system when your internet connection drops, unless your using outside monitoring, your not going to get that email to send you a page.

I ran into an issue with the modem not dialing quickly enough and had a few tips for getting it going.

1) Make sure that your calling the correct dialing group.

2) Check the modem in minicom, load it up, and do a few

AT[ENTER]
OK
ATZ[ENTER]
OK

to make sure the modem is reset, and then do a

ATDT 2125551212[ENTER]
{it should pause and dial the number [in this case, 212-555-1212] and either tell you BUSY, CONNECTED, or error out.

Just thought I’d toss out a few reminders.

Comments

Setting up ip aliases in freebsd

Often times in a server environment your going to need to setup multiple ip addresses to the same ethernet card, it’s really a simple procedure, and the way that I generally do these things is create a file called /etc/rc.aliases and include the alias line in there:

If the IP is on the same netmask:

/sbin/ifconfig fxp0 alias 192.0.3.9 netmask 255.255.255.255

Otherwise, just specify the network address and netmask as usual:

/sbin/ifconfig fxp0 alias 172.16.0.223 netmask 255.255.255.0

once you’ve added each line, then add a line in the /etc/rc.local file

sh /etc/rc.aliases

This way when you want to edit the aliases on each server you have them all in one location.

Comments (1)

FreeBSD servers and keyboards

One of the minor issues I have with freebsd out of the box is that when I have a server network of a few hundred servers, I can’t just plug in a keyboard when we’re having an issue with the networking.

This is a common issue, the freebsd kernel doesn’t support just plug and play keyboards, however there is an easy fix to this mess.. well, easy if your comfortable recompiling a kernel (which you should be).

# cd /usr/src/sys/i386/conf
# cp GENERIC MYKERNEL

vi MYKERNEL

search for:

device atkbd0 at atkbdc? irq 1 flags 0×1

and replace the line with:

device atkbd0 at atkbdc? irq 1

save it (:wq!)

and then

# /usr/sbin/config MYKERNEL

# cd ../compile/MYKERNEL
(For FreeBSD versions prior to 5.0, use the following form instead: # cd ../../compile/MYKERNEL)

# make depend
# make
# make install
If everything went cleanly..
# shutdown -r now

and it should come back with a kernel that allows you to just plug in a PS2 style keyboard without any issues.

Comments

NTP — Keeping your clock in sync

One of the most insane things about working in the unix world is that it complains when the system clock on your computer is wrong. There is nothing more disturbing then when you create a tarball on another machine and extract it on yours and it complains that the files were created in the future.

A great way to deal with this problem is a system called ntp, network time protocol.

Network Time Protocol (RFC-1305), or more commonly known as NTP is pretty simple to setup, most OS’s are simply an RPM or ports tree install away.

(freebsd)
Connect to your machine and su - to root, then:

# cd /usr/ports/net/ntp
# make

# make install
# rehash

once thats done, simply run:

# ntpdate time.nist.gov
5 Nov 19:46:40 ntpdate[46439]: step time server 192.43.244.18 offset -2.467839 sec
#

This will update your server to the current time.

My suggestion is to set this up as a nightly cronjob,

# vi /etc/crontab

and add the line:

0 2 * * * root /usr/sbin/ntpdate time.nist.gov > /dev/null

and restart cron (

# killall -HUP cron

And you should be good to go!

Comments

« Previous entries · Next entries »