Monday 26 November 2012

Trap, thread and monitor

I just want to dump three great resources for bash hacking. First of all a list with some handy resources. Second if about making your script aware of the ctrl-z combo and third a bash script that spawns a couple of threads.

1. http://bash.cyberciti.biz/shell/monitoring/
2. http://hacktux.com/bash/control/c
3. http://blog.apokalyptik.com/2008/12/11/using-wait-and-for-threading-in-bash/

It certainly helped me monitoring some disc space usage during an installation.

Wednesday 3 October 2012

Redirect bash output to file and screen

So you have made a nice new script in bash. Fancy you! Alas it has to log to a file and to screen. That might sounds simple, and it is, check this out:

exec > >(tee ${LOGFILE}) 2>&1

WTH? Well just redirect all output (error and out) to a subprocess which tee's it (write to screen and to log).

Use WLST functions inside Jython classes

Using WLST can be frustrated because all of the global functions that seemingly cannot be used inside classes. Putting functions in classes and making re-usable libraries is common practice in the current development world. Most developers would like to avoid spagetti-monsters; although some still seems to like the idea of spagetti with tomato sauce.

To use the global commands of WebLogic's WLST import the correct module:

import wlstModule as wlst

wlst.connect('weblogic','welcome1','t3s://localhost:7002')
wlst.redirect('/var/log/weblogic.log')

Thanks to: http://stackoverflow.com/questions/8252846/wlstmodule-connection-information-lost

Tuesday 2 October 2012

Remove files older then X days on Linux

I always forget how i can clean up my /var/log. Therefor i dump the code snippet i need to do this. And it is so very simple...

Delete all files older then 3 days in current and child directories:
find . -mtime +3 -exec rm -rf {} \;

Friday 14 September 2012

PC speaker beep is so annoying

When working on a linux machine and tabbing out your commands, it often happens that you hear the speaker beep. This can be very annoying. So let's turn it off. Remove the pc speaker modules "pcspkr" and "snd_pcsp". You might have only one of these modules in use, but they both enable beeps.

Open a terminal and issue this command as root:

# modprobe -r pcspkr snd_pcsp

To prevent the "pcspkr" and "snd_pcsp" modules from loading again at startup add them to modprobe's blacklist in /etc/modprobe.d/blacklist. You can do this with the following command:

# vi /etc/modprobe.d/blacklist
blacklist pcspkr
blacklist snd_pcsp


See: http://www.thinkwiki.org/wiki/How_to_disable_the_pc_speaker_(beep!)

Tuesday 28 August 2012

How to roll back packages on CentOS 5 / RHEL 5

CentOS 5 / RHEL 5 preferably uses yum as the program to update, install and remove packages.
When you’ve installed/updates packages with yum or rpm, you can quite easily roll back the updates/installations using rpm.
For this, yum and rpm need to save roll back information, which they do not do by default.
To enable the roll back feature, do the following:

Add tsflags=repackage to /etc/yum.conf.
Add %_repackage_all_erasures 1 to /etc/rpm/macros. If /etc/rpm/macros does not exist, just create it.

You can now install, erase and update packages with yum and/or rpm, and they will save roll back information.

When you want to roll back, use rpm to do so.
You do this by specifying the --rollback switch and a date/time, like the examples below:

rpm -Uhv --rollback '19:00'
rpm -Uhv --rollback '8 hours ago'
rpm -Uhv --rollback 'december 31'
rpm -Uhv --rollback 'yesterday'

Source: http://www.vincentverhagen.nl/2007/12/10/how-to-roll-back-packages-on-centos-5-rhel-5/

Thursday 1 March 2012

Telnet under Win7

It’s very rare that I use Telnet these days, so it took a long time for me to notice that by default it was not packaged with Windows 7. I did some research and found out that this was also true for Windows Vista. More than likely this was an attempt to make Windows more secure by default, as Telnet is very insecure and whenever you have the choice you should always use SSH. However, with that being said, you can quickly re-enable Telnet by following these steps:

- Start
- Control Panel
- Programs And Features
- Turn Windows features on or off
- Check Telnet Client
- Hit OK

After that you can start Telnet via Command Prompt.

Source: http://www.fettesps.com/windows-7-enable-telnet/