Howto: Check what services are accepting network connections

Use ‘netstat -tnlp’.

$ netstat -tnlp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:1521            0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:54904           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:17500           0.0.0.0:*               LISTEN      2366/dropbox
tcp6       0      0 :::139                  :::*                    LISTEN      -
tcp6       0      0 :::80                   :::*                    LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 ::1:631                 :::*                    LISTEN      -
tcp6       0      0 :::445                  :::*                    LISTEN      -

Using ‘grep’ with Subversion

I use ‘grep’ alot, but it false positives when searching in a Subversion working copy. So I’m using the ‘-r’ flag to recursive search for the phrase ‘quick brown fox’:

$ grep -r 'quick brown fox' *
app/controllers/users_controller.php: quick brown fox
app/controllers/.svn/text-base/users_controller.php.svn-base: quick brown fox

This is only a minor annoyance if there are just two entries, but often that’s not the case. The solution is to add the ‘–exclude-dir=.svn’ flag. But the extra characters causes unnecessary fatigue on my fingers, so I’ve added an alias to my .bashrc file:

alias grep='grep --exclude-dir=.svn'

For maximum mileage, combine this with ‘-ir’:

alias grep='grep -ir --exclude-dir=.svn'

Changing hostname

Should you update /etc/hostname — I did — be sure to update the default tnsnames.ora and listener.ora.

Mine were found in /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/network/admin.

Otherwise you’ll get an ORA-12541 message.

Disk usage sorted by file size

The following shell command runs the ‘du’ command to a max folder depth of 1, and then pipes the output to ‘sort’, and the finally writes it ‘du_log’.

$ du -h --max-depth=1 | sort -n -r > du_log

Tar with exclusion

Sometimes I want to duplicate a Subversion-ed directory, without the .svn folders in each subdirectory. The reason for this is when I want to add/commit this newly duplicated folder, I get an error message because the .svn directory indicates that the files are already in the repository — when it is NOT.

We can do this easily by using tar and the exclude flag:

$ tar -cvf foo.tar ./* --exclude=.svn

Muting the system buzzer

When in the command shell, it is too easy to press Tab to autocomplete too many times. I love the text auto complete feature — it saves my fingers — but I overuse it. This results in the annoying “beep” from the system buzzer. Mute it with the command:

$ /usr/bin/setterm -blength 0

You could also append it to the end of your .bashrc — assuming you’re using bash of course — so it runs every time you login.

If, like most Linux users you use Gnome Terminal or KDE Konsole, try exploring around, there are options to mute the system buzzer (or bell), and save the option to mute it as default.

Demystifying rc*.d — startup scripts for everybody

First you gotta have some kind of shell script that you want to run on startup; say /etc/init.d/httpd.

Apache2 should run on boot, so we make a symbolic link to it in one (or more) run levels; e.g. /etc/rc5.d/.

# whoami
root
# cd /etc/rc5.d/
# ln -s ../init.d/httpd S85httpd
# ls -la | grep httpd
lrwxrwxrwx  1 root root   15 Mar 12 10:11 S85httpd -> ../init.d/httpd

Now the /etc/init.d/httpd script will run the next time the system boots to run level 5.

Recursive chmod

When considering the chmod -R command, you may actually be wanting to descend, from some directory into all of its subdirectories to set the file permissions for a particular type of file. Directories should be 755, of course.

Try using:

$ find . -type f -print
$ find . -type f -name *.php -print

#1 will search the present working directory (.) for documents of type file (f) and print onto the standard output.
#2 will search the present working directory (.) for documents of type file (f), with filename ending with “.php” and print onto the standard output.

When you are satisfied that your find command is correct, add the xargs parameter to the end:

$ find -type f -print | xargs chmod 644

This will set file permissions in ALL subdirectories to be 644 or -rw-r–r–.

From support.daemonnews.org.

PHP4 issue (v4.4.5)

I just spent the last 3 hours trying to figure out how come, after upgrading the PHP version on my web server, two websites were broken.

In particular, these two were done using my colleague’s new framework — which is pretty good — but they just wouldn’t work.

Apache2 would prompt to download the .php file, and when I saved it, it was blank. Great. In the 2nd website, the page would be blank instead.

Now, I’m not really very cool about upgrading PHP, in fact I’d much rather get my sysadmin to do it, but tonight called for urgency. Yeah. So it was up to me.

So i used almost the same ./configure parameters except I wanted the imap_* functions:

# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql \
--with-curl --disable-debug --enable-ftp --enable-inline-optimization \
--enable-magic-quotes --enable-mbstring --enable-mm=shared \
--enable-safe-mode --enable-track-vars --enable-trans-sid \
--enable-wddx=shared --enable-xml --with-dom --with-gettext \
--with-regex=system --with-xml --with-zlib-dir=/usr/lib \
--with-zlib-dir --with-ttf --with-freetype-dir=/usr/local/include/freetype2 \
--with-imap-ssl=/usr/local/imap2006e/
# make
# make install

All went fine of course. I tried with different options, with-apxs2, with-mysql and with-imap. Didn’t work as well. Then I sought Google:

“php script downloaded instead of rendered”

Nothing much actually. Maybe it was the search keywords. There was a post on the WordPress forum about Apache, okie so I decided to upgrade Apache as well. Risky, but it was late, so what the heck. Pissed off already. After compiling the new Apache 2.0.x version, I recompiled PHP. Nope, didn’t work.

So I figured I’d to trace the PHP script, comment/uncomment until I came to this one line:

session_register("foo", "bar");

Ahhah! Later I went into the Apache2 logs and lo and behold, there was a segfault error message which I had blithely not thought to read. Yeah. This bug is resolved in CVS, but I’m really pissed now, so I reverted to v4.4.4, and it worked like a charm.

Doh.

Z Shell on Fedora Core 6

Z Shell zsh.org. Apparently this is a very good alternative to bash, but this is all about getting out of the comfort zone, so here goes:

# tar zxvf zsh-4.2.6.tar.gz
# cd zsh-4.2.6
# more INSTALL
# ./configure
# make
# make check
# make install
# pico /etc/shells
-- added /usr/local/bin/zsh to the list of availables shells (/etc/shells).
# chsh
Follow

Get every new post delivered to your Inbox.