Arquivo

Arquivo do Autor

Ubuntu / Linux desligando Wireless quando usa Bateria

Praticamente sempre que desconecto meu notebook (Thinkpad T430) da tomada, e deixo somente na bateria, o Wireless torna-se instável e é desligado. Quem faz esse desligamento é o utilitário /usr/sbin/pm-powersave. Você pode constatar isso efetuando o comando “ls -lrt /var/log” assim que o evento ocorrer. Verifique as ultimas linhas dos logs modificados e vai achar o vilão!

Para resolver, basta executar o comando:

sudo /usr/sbin/pm-powersave false

Você deve também criar um arquivo vazio em /etc/pm/power.d/wireless , dessa forma, o powersave não desligará o Wireless.

Enjoy!

Anúncios
Categorias:Linux Tags:, , ,

Adding a scheduled task to Cron at Linux

Lets suppose that you have to run some task (a script for example) called test.sh every day at 6 and 12. You can use Linux Cron to schedule it.

Enter the command crontab -e to edit your cron schedule, then, add the lines:
00 6 * * * //test.sh
00 12 * * * //test.sh

Then, just save the file and voilà!

Cron its very flexible, you can configure minutes, seconds, days, months and years, and create complex schedules!

Enjoy!

Process check script for Linux

Sometimes I need to keep checking the some process is running in my servers. So, I created the following script and add it to Crontab. If I have problems, Ill receive an email.
This can be useful to someone!
In my example, Im searching for a process called zookeeper.

#!/bin/bash
SERVER="PROD 134"
ZK=`ps aux | grep zookeeper | grep -v "grep" | wc -l`

if [ $ZK -ge 1 ]
   then
        echo "ZK is Running"
   else
        echo "ZK is not Running" | mail -s "Zookeeper is not running - $SERVER" myemail@br.ibm.com
fi
Categorias:Linux Tags:, , , ,

Disk Space script for Linux

Sometimes I need to keep checking the disk space at my servers. So, I created the following script and add it to Crontab. If I have problems, Ill receive an email.
This can be useful to someone!

#!/bin/bash
# In my case im interested in a specific partition /opt/XYZ
SPACE=`df -h | grep /opt/XYZ | awk '{print $4}' | awk -F % '{print $1}'`

case $SPACE in
        9[1-9])
        echo "Disk space > 90 %, please check" | mail -s "Disk Space problem" email1@br.ibm.com,email2@br.ibm.com;;
        100)
        echo "Disk Full, please check" | mail -s "DISK FULL" email1@br.ibm.com,email2@br.ibm.com;;
esac
Categorias:Linux Tags:, , , ,

Adding DB2 jdbc drivers to a Maven Java project

You need to get the DB2 drivers, in my case db2jcc.jar and db2jcc_license_cu.jar, then, drop it to a folder at your file system, also, in my case I created a folder /opt/driveDB2 and drop the 2 files there.

Then, run the mvn install command, like in my examples (pay attention in your Version):

mvn install:install-file -Dfile=/opt/driveDB2/db2jcc.jar -DgroupId=com.ibm.db2.jcc -DartifactId=db2jcc4 -Dversion=10.1 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true

mvn install:install-file -Dfile=/opt/driveDB2/db2jcc_license_cu.jar -DgroupId=com.ibm.db2 -DartifactId=db2jcc_license_cu -Dversion=10.1 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true

At your project, just add the following lines to the pom.xml file:

<dependency>
    <groupId>com.ibm.db2.jcc</groupId>
    <artifactId>db2jcc4</artifactId>
    <version>10.1</version>
</dependency>

<dependency>
    <groupId>com.ibm.db2</groupId>
    <artifactId>db2jcc_license_cu</artifactId>
    <version>10.1</version>
</dependency>

Voa lá!

Categorias:DB2 / Banco de dados, JAVA Tags:, ,

Java + JDBC: imprimindo informações de tabelas

Preciso pegar as informações das tabelas/colunas nas quais fiz uma query, e sempre esqueço… Fica a dica aqui com um código bem bobinho. sugestões são bem vindas.

		Statement stmt = connection.createStatement();
		ResultSet rs = stmt.executeQuery("SELECT * FROM TABLE FETCH FIRST 10 ROWS ONLY");

		ResultSetMetaData rsmd = rs.getMetaData();
		int columnCount = rsmd.getColumnCount();

		// The column count starts from 1
		for (int i = 1; i <= columnCount; i++ ) {
		  String name = rsmd.getColumnName(i);
		  System.out.print(name + "|");
		}
		System.out.println();
		
		while (rs.next()) {
			String toPrint = "";
			for (int col = 1; col <= columnCount; col++) {
				toPrint += rs.getString(col) + "|";
			}
			System.out.println(toPrint);
		}

Creating a collection in IBM Watson Explorer crawling from Database

Perform a database Craw from a collection its something very common. With IBM Watson Explorer this is something very easy to do. In my example, Ill create a collection and will perform a simple query in a IBM DB2 database, but, the steps will be very similar for other databases, you just need to keep in mind that you will need the correct driver.

1- Put the driver in place:

Get the database jdbc and put in the correct folder, usually it is something like /opt/IBM/dataexplorer/WEX-11_0_2/Engine/lib/java/database/.

2- Create the collection copying defaults from default:

Selection_188.jpg

3- Add a new seed, this is where your collection will get data:

Selection_189.jpg

4- Choose Database:

Selection_190.jpg

5- Enter your database settings and the query that will be performed:

Selection_191.jpg

6- Its done, now you can test:

Selection_192.jpg

7- This can take a while depending on your query and connection, but when it finish, it will show some rows that the query returned in the following format. To see some row data, click Crawler XML:

Selection_193.jpg

8- Here is your data:

Selection_194

9- Now that we see that its working, you can start your craw. This step will feed your collection and can take a good time depending on your amount of data:

Selection_195

10-You must see Craw activity:

Selection_196

11- You can query your collection now to test, just enter your term and click search in the left options:

Selection_197

12- You will see something like this:

Selection_198

Thats it, you have created a collection that get data from Database!