A few months ago, the Server OS was changed from Ubuntu 10.04 to CentOS 6.3. After wine is installed, you can run the shell script manually to run the specified exe program (the script is the same as that in Ubuntu ), therefore, the script is automatically run when crontab is modified.
Recently, it was found that the exe was not automatically executed once (Dahan, which serves as a backup database and clearing outdated backup). So I immediately searched for the cause of the problem and preliminarily estimated the following points:
1. crontab configuration error
The original configuration is to run every 2 hours, instead of every 3 minutes. View the crontab log (/var/log/cron series logs). It is found that the script in the crontab configuration is run every three minutes (recorded in the log ). Run the script on the GUI. The function is normal. The conclusion is that there is no error in crontab configuration, and the script runs every two hours.
2. wine failed to run the exe program.
In the shell script, redirect the normal output and abnormal output of wine running exe to the specified file (&> append to the end of the file ). So we found the initial cause:
Wine: '/' is not owned by you, refusing to create a configuration directory there
The strange error is that winecfg has already been run on the user interface, and the wine configuration folder is automatically generated. So google (PS: I used Baidu to search for "wine: '/home/username' is not owned by you" in the Ubuntu Chinese forum !" The solution is to check whether the user's home directory belongs to and the permissions are correct.) The simple solution is to set a wine variable -- $ WINEPREFIX before execution. The specific method is
Export WINEPREFIX =/home/username/. wine
Or
Env WINEPREFIX =/home/username/. wine
This will only take effect in the current shell and its sub-shell. Finally, we can execute wine ...... Check the log and find that although wine can run, an error is reported. What is the output of the exe program in Chinese ?.
I chose to solve the problem of Chinese garbled characters output by exe, that is, character encoding. Output in shell script
Echo $ LANG &> yourlog
So found the difference between manual operation and automatic operation, manual is the zh_CN.UTF-8, automatic is the en_US.UTF-8 ...... Easy to do, the same processing method, set the variable LANG to zh_CN.UTF-8 before execution, successfully output Chinese.
Then solve the wine Error
Err: menubuilder: write_free1_top_mime_type_entry error writing file //. local/share/mime/packages/x-wine-extension-cpl.xml
At this time, I began to suspect that some necessary initialization operations were missing when the crontab of CentOS executed the command of the specified user. Again, google found similar problems on wine's official website
Err: menubuilder: write_free1_top_mime_type_entry error writing file/home/mark/. local/share/mime/packages/x-wine-extension-cpl.xml
After careful comparison, mark's xml file is in its home directory! Output The main directory
Echo $ HOME &> yourlog
Manual is/home/username, automatic is ...... Blank, no words ask cangtian. For the same processing method, set the variable LANG to/home/username before execution to solve the wine error.
Conclusion
At this point, we can confirm that the crontab of CentOS lacks some necessary initialization operations when executing the specified USER command, such as the user language, user main directory, and command PATH. I can only make sure that whoami is output correctly (Dahan). If you encounter a similar environment variable initialization problem (not just wine), you can open/etc/profile and/etc/profile. d. Some other variables, such as HOME and WINEPREFIX, do not find the initialization statement. Please leave a message if you know it.
Since crontab runs in the background and does not provide a graphical interface, if the exe program has a graphical interface, you may have to add "DISPALY =: 0" before the wine statement.
DISPLAY =: 0 wine ***. exe> yourlog. log
PS1: My crontabs version of CentOS 6.3 is 1.10-33. el6, And the cron of Ubuntu 10.04 is 3.0pl1-ubuntu5
PS2: wine does not report an error when "HOME" is set correctly but "WINEPREFIX" is not set. This was discovered when I tested this article again, so "I can improve myself when I teach others ".
Recommended reading:
Use wine to run Windows programs on Linux/Mac
Use crontab in Linux to create scheduled tasks
Ubuntu uses crontab for scheduled tasks
Linux crontab settings
Linux crontab installation instructions