Saturday, July 10, 2010

CRON - How to (Summary) on Debian



Setup
 
To edit schedule setup, type:
 crontab -e

Format: 
#minutes hour day_in_the_month month day_in_the_week command 



By Example:
 
# m h dom mon dow command
MAILTO="name@isp.com.br"

#Executing everyday at 01:05 AM: 
5 1 * * * /usr/bin/pgm 2>&1 >> /var/log/cron.log 
 


# 00:30 AM on 1st day of Jan, June and Dec. 
30 0 1 1,6,12 * command 


# 08:00 PM on every weekday Mon and Fri in Oct. 
0 20 * 10 1,5 command 


# midnight on 1st, 10th and 15th every month. 
0 0 1,10,15 * * command 


# 00:05 and 00:10 AM every Monday on 10th of every month.  
5,10 0 10 * 1 command 


# redirecting stderr and stdout to the same file
3 0 3 * * * command 2>&1 >> /var/log/cron.log
4 0 2 * * * /usr/bin/browserbkp 2>&1 >>
/var/log/cron.log



Variables etc.

cat /etc/crontab

You can define or override environment variables, by defining them in the crontab file, one variable per line, in the format:

VARIABLE=value




Environment Variables
 
The following environment variables affect the execution of crontab:

EDITOR
Determine the editor to be invoked when the -e option is specified. The default editor is vi.

LANG
Provide a default value for the internationalisation variables that are unset or null.
If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used.
If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of
the variables had been defined.

LC_ALL
If set to a non-empty string value, override the values of all the other internationalisation variables.

LC_CTYPE
Determine the locale for the interpretation of sequences of bytes of text data as characters
(for example, single- as opposed to multi-byte characters in arguments and input files).

LC_MESSAGES
Determine the locale that should be used to affect the format and contents of diagnostic messages written
to standard error.

NLSPATH
Determine the location of message catalogues for the processing of LC_MESSAGES .





First Use
 
Run once the command:

crontab -u user -e

After this first time, edit with:

crontab -e

More commands:  

crontab -h
 

Note:
Tests done, using graphical interface to warn about occurred errors didn't work under cron, MAKING IT FAIL.
By now, just use shell scripts with text messages.
Even dialog was tested, and cron fails to trigger the task. (08/07/10 22:50)



Defining Default Editor

export EDITOR=vim




Email
Receive only one cronjob's output in your mail, make sure this package is installed:

aptitude install mailx

And change the cronjob like this:

*/10 * * * * /bin/execute/this/script.sh 2>&1 | mail -s "Cronjob ouput" yourname@yourdomain.com


Stopping cron
 

crontab -r

The crontab -r will deactivate the cronjob and remove the file contents from the server.

Cron fails

Possible causes:

 
Exception or script mal-function
Editing crontab, redirect the stderr to the cron's log or another file log.
Check the script manual, running on the environment out of cron.

References to paths
Use absolute paths defined inside the script.

Different environment:
- The environment is different because the users login scripts
(.profile, .cshrc, .bashrc, etc) don't get sourced by cron
- Some versions of cron expect the script to be in 'sh', and ignore
the #! line at the top. You might have to write an 'sh' wrapper for
your script.
- Something in the script expects a TTY to be associated, and doesn't
work without one.



CRON FAILS - WHAT TO DO?
 
If using debian, the environment variables are usually already set, but it's a good practice to check them again.

To discover what happend, redirect stderrr to a log file.
For instance:

05 16 * * * /absolute_path/command options 2>&1 >>/absolute_path/cron.log
22 22 * * * /absolute_path/command options 2>>/absolute_path/cron.log


Path's errors
 

The output redirected to a log file returned this:

/usr/bin/bkpenvSizeWatcher: line 5: /bin/java: No such file or directory

Include the absolute paths on the script and overwrite the enviroment variables with local values.
Example:

JAVA_HOME=/home/server/jdk1.6.0_20 #0 this line overwrites environment variables (required by cron executions)
...
"$JAVA_HOME"/bin/java -jar file.jar [arguments]


X11 DISPLAY error
 
If running a java file, you can get this stderrr message:

Exception in thread "main" java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
at java.awt.Window.(Window.java:432)
...
 
Insert into the script the following local variables:

JAVA_HOME=/home/server/jdk1.6.0_20 #0 this line overwrites environment variables (required by cron executions)
export DISPLAY=:0 # required by cron execution (debian)
 


If you still get stderr messages like this:

Exception in thread "main" java.lang.InternalError: Can't connect to X11
window server using '0:0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$100(X11GraphicsEnvironment.java:52)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:155)
 

Try others diplay settings:

export DISPLAY=0:0
or
export DISPLAY=:0.0
 
If Red Had, try: 

install Xvfb rpm (X virtual frame buffer)

Add to /etc/profile file:
# Start the X virtual frame buffer (Xvfb)
if [ -f /usr/X11R6/bin/Xvfb ]; then
/usr/X11R6/bin/Xvfb :1 -screen 0 1024x768x16
fi
# Set the DISPLAY variable:
export DISPLAY=localhost:1.0

Friday, June 25, 2010

SVN WARNING MESSAGE: Clear update statuses operation failed

PROBLEM:

You get a warning message after an SVN operation like below:

Clear update statuses operation failed.
 0x00000004: The resource is inaccessible: resource_path ...



SOLUTION:

This happened after I excluded a project from the workspace and the repository, respectively, using Eclipse with subversion plugin.
The solution was achieved when I recreated the missing path, including it as project and into repository, using exactly the same original notations.
Then I committed the projects which caused the warnings and the messages stopped, but the fake projects were still there.
I deleted them and closed eclipse.
When reopened, I checked the same projects and problem had gone.
I've tried the method twice, successfully.

Sunday, May 9, 2010

VMWare and Windows Defragmentation - The Virtual Machine is slower

It is common to defragment the Windows (the host) without proceeding the VM defragmentation before.
Why?
Because we forget the VM guests when we are not using them.

So, when the VM is opened next time, its performance is slower than normal.
Don't worry.
If the client is Windows, proceed the client's defragmentation.
If Linux, it's rarely necessary. Usually not.
Turn off the VM, shutdown the client, not suspending or hibernating it.
Proceed a second defragmentation using the VMWare's defragmentation command.
By example:

"C:\Program Files\VMware\VMware Workstation\vmware-vdiskmanager.exe" -d "D:\virtualMachines\debian5\debian5.vmdk"
After a successful result, you can finally perform the host defragmentation, and the VM's performance will come back.

Tuesday, May 4, 2010

Start an iconified application on Windows using batch

Suppose that you want to start an application on Windows using a batch which shows its icon on desktop.
Follow the example.

1. Create the batch file that contains the command to start the application.
In this example, I've created the batch file 1___timer_scheduled.bat.

2. Create a link to this command (use the pop-up menu) referencing the application's icon using the Change Icon button (red arrow).



3. Create another batch file referencing the link created before, using this command:

start "Timer6030" /D"D:\miniTools\timer\" "D:\miniTools\timer\1___timer_scheduled.lnk"

Of course, this example uses my environment paths. Switch to yours.

Note: The trick is not using the "/B"  option of the start command.

This batch creates a new window which uses the link's configuration and not the system's default configuration.

It's done.
Use the last batch created (step 3) to start the application.
The link created on step 2 works for a manual starting from the desktop, but it fails on Task Scheduler.
Check the figures below.


Using the link created on step 2 - the icon fails (red arrows): 

   



 Using the link created on step 3 - desired icon is shown:
   

Monday, May 3, 2010

JavaFX Running In Opera 10.5

How to enable JavaFX on Opera?

To enable JavaFX, it's used dragonfly plugin enhancements.
So, do:

1. Update your Opera to version 10.5 or upper.

2. The version 10.5 comes with dragonfly but you need just to enhance the menu's option.
    So, install this augment from:
    Opera dragonfly augment

Note: after installation the dragonfly view can be opened.
To switch, check/uncheck the option on: Tools, Advanced, Opera dragonfly
This will open or close the Opera dragonfly view.

3. After the enhancement is installed, the "Debug" option on menu comes available.
    Go to:  
    Debug, User Agent and check the option "Identify as Internet Explorer".

It's done.
Now you can open a JavaFX page.

This post was based on:
ICED IN CODE - JavaFX Running In Opera 10.5

Wednesday, April 28, 2010

jEdit's - Replicating installations

Suppose that you already have an installation containing your plugins and configurations.
If you desire to replicate this installation to another machine, for instance a virtual machine, without having to do everything again, there is an alternative that works well if the new installation has the same path of the old. If not, some path adjustments may be necessary according to your environment.

1. Install jEdit as usually.
2. Copy the jEdit's user configurations under .jEdit folder overwriting the content of the respective .jEdit folder of the new installation.
For instance, on Vista you find .jEdit folder configuration under C:\Users\User_Login\.jedit, and on XP under C:\Documents and Settings.
3. Copy the full content under the INSTALL_DIR/jEdit, overwriting the full content of the respective INSTALL_DIR/JEdit of the new installation.

It's ready to run.
I use this procedure to replicate my jEdit's intallations on virtual machines.

Sunday, April 25, 2010

jEdit full plugin installation - getting through

I got 3 problems from a full plugin installation using jEdit version 4.3.1:

#1 - "Cannot run global"

If a "A Cannot run global" message keeps poping up after installing all plugins, then uninstall the 'GlobalPlugin'.
To remove it, use the Plugin Manager and restart jEdit.

#2 - Error message "Class or variable not found: p4plugin.P4FileInfo"

Sourced file: inline evaluation of: 'new p4plugin.P4FileInfo(); ...
Class or variable not found: p4plugin.P4FileInfo ...

To solve this, I tried to find p4plugin and remove it, but the Plugin Manager didn't show the respective plugin as p4Plugin.
After other attempts, the solution was the manual deletion of the respective jar (INSTALL_DIR/jEdit/jars/P4Plugin-0.3.1.jar), because the Plugin Manager couldn't help.

#3 - Some plugins failed

Some plugins didn't install successfully. Just 4 of them.
So, I removed them using the "Plugin Manager".

NOTE:
Check the status of the plugins after any installation.
If someone shows any kind of error status, remove it or try to install again.

These procedures permitted me to perform a successful (almost) full plugin installation at one step, although it's not advisable.

Friday, March 5, 2010

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

PROBLEM:
If working with Hibernte, you got this message:
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 

SOLUTION: 
solve the problem adding this two jar files to the project's library:
   slf4j-api-1.5.10.jar
   slf4j-simple-1.5.0.jar


You find those jars on  http://www.slf4j.org/manual.html 

Go to the download page and download the file "slf4j-X.Y.Z.zip" (or the tar file).
Be sure that the version matches you project's environment.

How?
Simple: check the project jars' versions, compare and try! : )
 

 

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...