Use yum to install a local package (rpm)

Posted by admin under Ramblings

Use yum to install a local package, automatically checking/satisfying dependencies and allowing easy uninstall.

yum --nogpgcheck localinstall packagename.arch.rpm

No Comments

List all cron jobs on a Linux Server

Posted by admin under Ramblings

While searching through a server trying to find a failed cron job the thought occurred to me that it’d be nice to have a list of all the cron jobs on the box regardless of owner. Google turned up this answer, which worked beautifully.

for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done

No Comments

List all triggers in a Postgres DB

Posted by admin under Ramblings

Today I was trying to see if there were any triggers in this on db that touched a particular table. This command came in handy:

SELECT relname, tgname, tgtype, proname, prosrc, tgisconstraint, tgconstrname, tgconstrrelid, tgdeferrable, tginitdeferred, tgnargs, tgattr, tgargs FROM (pg_trigger JOIN pg_class ON tgrelid=pg_class.oid) JOIN pg_proc ON (tgfoid=pg_proc.oid);

But, the results were more than 600 rows. So let’s make it more selective, shall we:

SELECT relname, tgname, tgtype, proname, prosrc, tgisconstraint, tgconstrname, tgconstrrelid, tgdeferrable, tginitdeferred, tgnargs, tgattr, tgargs FROM (pg_trigger JOIN pg_class ON tgrelid=pg_class.oid) JOIN pg_proc ON (tgfoid=pg_proc.oid) WHERE prosrc LIKE '%XXX%'

The this one only grabs the rows where the trigger has ‘XXX’ in it.

No Comments

Calculating the number of IP addresses in a block

Posted by admin under Ramblings

So I’m always hearing people talk about blocks of ip addresses such as /23 or /32 or /24. But other than just memorizing them all I wasn’t really sure how to tell how many IPs were in each block. Today I learned that there is a formula.

2^(32 – x) where x is whatever’s after the /

So if we’re dealing with, say a /24 then we have

2^(32-24) = 2^8 = 256 addresses.

That said, I’ll be glad when everyone finally moves over to IPv6.

No Comments

Database differences in LIMITing results

Posted by admin under Ramblings

Assuming we want the first 10 records from a result set:

MySQL

SELECT
	col
FROM
	tbl
LIMIT 10

Oracle

SELECT
	*
FROM
	(SELECT
		col
	FROM
		tbl)
WHERE
	ROWNUM < = 10

Microsoft SQL

SELECT 
	TOP 10 col
FROM tbl

What’s that? Why yes, yes Oracle is a pain.

No Comments