Archive

Archive for the ‘One Liners’ Category

Null delimit find output

November 8th, 2009 admin No comments

If you are attempting to pipe the output of find to another command
such as xargs, and your files have quotes, spaces, or other “nonstandard”
characters in them, you can null terminate (rather than newline terminate) your
find output with -print0. You can then use the -0 option
to xargs to read the NUL delimeted output.

For example, I had a bunch of 1252 byte files in a directory with spaces in their
filenames. So…

# find . -size 1252c -print0 | xargs -0 rm

Too easy!

Cheers,
Kevin

Categories: GNU Tools, One Liners Tags:

Updating a file on all zones at the same time

November 3rd, 2009 admin No comments

I recently modified /etc/resolv.conf on all of my global zones after building new nameservers. I wanted a quick way to copy this updated configuration to all child zones. A simple one-liner does the trick on each global zone (assuming all your zones are in the /var/zones zonepath):

# zoneadm list | grep -v global | while read zone; do cp -p /etc/resolv.conf /var/zones/${zone}/root/etc; done

Cheers,
Kevin

Categories: One Liners Tags:

Checking an HTTPS webserver

November 3rd, 2009 admin No comments

It’s easy to telnet to port 80 on a “standard” non-SSL webserver, and issue a GET / in order to verify that the webserver is responding correctly. But how to do it over SSL? Just use the s_client command via the openssl tool

# openssl s_client -connect www.example.com:443

You’ll see details of the certificate chain displayed (as well as any errors), and you can then issue your GET / to test the webservers operation.

You can also use this tool to test other SSL-enabled services (such as IMAPS/POP3S).

Cheers,
Kevin

Categories: Apache, One Liners Tags:

Removing Bounces From the Mail Queue

November 3rd, 2009 admin No comments

The following simple one liner will do the trick:

# mailq | grep MAILER-DAEMON | awk '{print $1}' | sed 's/\*//' | postsuper -d -

Cheers,
Kevin

Categories: One Liners, Postfix Tags:

Generate hashed passwords

November 3rd, 2009 admin No comments

Another OpenSSL related tip.

If you’ve ever wanted to generate a hashed password suitable for inclusion in the /etc/shadow file (for example, during post-install procedures such as sysidcfg), you can use the openssl passwd command

$ openssl passwd
Password:
Verifying - Password:
HaShEdPaSsCoMeSoUt

Cheers,
Kevin

Categories: One Liners, Security Tags:

Fix Perl Make Errors Under Solaris

November 3rd, 2009 admin No comments

When you build Perl modules under Solaris, they are optimised for Sun Studio, which of course, we all use :/

So, if you build with gcc, the build will likely fail.

You can use the following magical one-liner to fix this brain damage, and your modules will build correctly.

# pwd
/usr/local/src/cpan/Some-PerlMod-0.123
# find . -name "Makefile" | while read MAKEFILE; do
>   sed 's/^CC = cc$/CC = gcc/' ${MAKEFILE} > ${MAKEFILE}.tmp
>   sed 's/^LD = cc$/LD = gcc/' ${MAKEFILE}.tmp > ${MAKEFILE}
>   sed 's/^CCCDLFLAGS = -KPIC$/CCCDLFLAGS = -fPIC/' ${MAKEFILE} > ${MAKEFILE}.tmp
>   sed 's/OPTIMIZE = -xO3 -xspace -xildoff$/OPTIMIZE =/' ${MAKEFILE}.tmp > ${MAKEFILE}
>   sed 's/ -xarch=v8//' ${MAKEFILE} > ${MAKEFILE}.tmp && mv ${MAKEFILE}.tmp ${MAKEFILE}
> done

Cheers,
Kevin

Categories: One Liners, Perl, Solaris Tags:

Checking md5 sum on Solaris 10

November 3rd, 2009 admin No comments

If you don’t have the md5sum utility installed, just use the digest tool supplied with Solaris 10

$ digest -a md5 -v /bin/ls
md5 (/bin/ls) = b57e173220af4b919f1d4bef9db11482

Cheers,
Kevin

Categories: One Liners, Security, Solaris Tags:

Selective removal of files

November 3rd, 2009 admin No comments

I wanted to remove a large number of files from a directory. However, I did not want to descend into subdirectories, nor did I want to remove any .pdf or .chm files. Some of the files had non-standard characters (such as quotes and spaces) in them.

The solution? A simple one liner using find and xargs

$ find . \( ! -name "*.pdf" -a ! -name "*.chm" \) -maxdepth 1 -type f -print0 | xargs -0 rm

Cheers,
Kevin

Categories: One Liners Tags:

wget – recursive get without traversing parent directories

November 3rd, 2009 admin No comments

When grabbing files with wget, it is useful to sometimes not traverse parent directories. For example, say I want to download everything under http://www.example.com/my/home recursively, but not traverse upwards into parent directories. You can add the –no-parent option for this.

$ wget -r --no-parent http://www.example.com/my/home

Cheers,
Kevin

Categories: One Liners Tags:

Remove empty files

November 3rd, 2009 admin No comments

Simple one liner to remove empty files older than 7 days

# find . -type f -mtime +7 -ls | awk '$7 == 0 { print $NF }' | xargs rm

Cheers,
Kevin

Categories: One Liners Tags: