Archive for the ‘Get Stuff Done’ Category

Jboss and jboss-log4j.xml stuff.

Tuesday, April 7th, 2009

I recently had the need to segment a jboss server so the applications logged to their own files.
By default jboss will log all the application level logs to server.log. Edit the jboss-log4j.xml
and add appenders for each application. For instance lets say my applications are applicationone
and applicationtwo. The lines between <!– and –> are comments in xml. After adding the appenders
you need to add appender-ref lines for each application. Easy Peasy.

<!– My first attempt at an appender for applicationone.ear –>
<appender name=”applicationone” class=”org.apache.log4j.FileAppender”>
<errorHandler class=”org.jboss.logging.util.OnlyOnceErrorHandler”></errorHandler>
<param name=”Append” value=”false”/>
<param name=”File” value=”/opt/jboss/server/default/log/applicationone.log”/>
<layout class=”org.apache.log4j.PatternLayout”>
<param name=”ConversionPattern” value=”%d{ABSOLUTE} %-5p [%c{1}] %m%n”/>
</layout>
<filter class=”org.jboss.logging.filter.TCLFilter”>
<param name=”AcceptOnMatch” value=”true”/>
<param name=”DeployURL” value=”appliationone.ear”/>
</filter>
<!– end the filter chain here –>
<filter class=”org.apache.log4j.varia.DenyAllFilter”></filter>
</appender>

<!– My first attempt at an appender for applicationtwo.ear –>
<appender name=”applicationtwo” class=”org.apache.log4j.FileAppender”>
<errorHandler class=”org.jboss.logging.util.OnlyOnceErrorHandler”></errorHandler>
<param name=”Append” value=”false”/>
<param name=”File” value=”/opt/jboss/server/default/log/applicationtwo.log”/>
<layout class=”org.apache.log4j.PatternLayout”>
<param name=”ConversionPattern” value=”%d{ABSOLUTE} %-5p [%c{1}] %m%n”/>
</layout>
<filter class=”org.jboss.logging.filter.TCLFilter”>
<param name=”AcceptOnMatch” value=”true”/>
<param name=”DeployURL” value=”applicationtwo.ear”/>
</filter>
<!– end the filter chain here –>
<filter class=”org.apache.log4j.varia.DenyAllFilter”></filter>
</appender>

<root>
<appender-ref ref=”CONSOLE”/>
<appender-ref ref=”FILE”/>
<appender-ref ref=”applicationone”></appender-ref>
<appender-ref ref=”applicationtwo”></appender-ref>
</root>

PowerShell 7za and scp

Sunday, December 21st, 2008

I wrote a PowerShell script to perform backups on a Windows computer to a Linux computer. The external requirements are 7za.exe and pscp.exe. Change below the commented lines with something that makes sense for you. PowerShell comments start with #. I take no responsibility for what this script does to you or because of you.

#Change the path below to the 7za.exe.
$zip = “c:\path\to\7za.exe”
#Change the path below to the pscp.exe.
$cpy = “c:\path\to\pscp.exe”
#Change below to your Linux server.
$server = “youlinuxserver”
#Change below to the path you want to copy to.
$path = “:/path/on/linux/server”
#Change to user you log into your Linux server with.
$user = “user”
#Change to pass you log into your Linux server with.
$pass = “password”

if($args.length -lt 2){
echo “Usage powerbackup.ps1 archivename source”
exit
}
$archive = $args[0]
$source = $args[1]

& $zip a -tzip $archive $source
& $cpy -pw $pass $archive`.zip $user`@$server$path
rm $archive`.zip

Parsing a log.

Friday, December 19th, 2008

Today I wanted to grep through an imap log to see if there are people with mailboxes whom have never logged into the imap server.  I had a list of users in /tmp/users.  I fine mix of a for loop, awk, and grep.  Here is what I came up with:

for i in `cat /tmp/users`; do echo “$i occurs `grep $i /var/log/imaplogs* | wc -l` times” ; done | grep ” 0 times” | awk ‘{print $1}’