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 {} \;