Implementation to the daemon, timed detection openoffice whether to exit, if the process does not exist, through the script will openoffice up. Procedure: First step:
Place the openoffice.sh script under the root directory (also at your own discretion):
Script content:
[Java]View PlainCopy
- #!/bin/sh
- #set-X
- Openofficepid= ' Ps-ef|grep "/opt/openoffice4/program/soffice" |grep-v grep|grep-v grep|awk ' {print $} '
- if [!-n "$OPENOFFICEPID"]; Then
- Echo "Openofficepid is empty"
- Echo "Start OpenOffice"
- /opt/openoffice4/program/soffice-headless-accept="SOCKET,HOST=127.0.0.1,PORT=8100;URP; Staroffice.service "-nofirststartwizard &
- Else
- #kill all OpenOffice Process
- # ps-ef|grep "/opt/openoffice4/program/soffice" |grep-v grep|grep-v grep|awk ' {print $} ' | Xargs kill /c1>
- Echo "Openofficepid is $OPENOFFICEPID is started!"
- Fi
Step Two: Assign permissions
Chmoda+x openoffice.sh
Step three: Edit the crontab file
Command Line input: crontab–e
Enter the following: */5 * * * */bin/sh/root/openoffice.sh NOTE: every 5 minutes to execute this script, can be modified according to actual needs;
Wq Save exit;
File Edit path:
Fourth step: View scheduling tasks
Crontab-l//List all current Scheduled tasks
:
Verify:
Pass
Ps-ef|grep "/opt/openoffice4/program/soffice" |grep-v grep|grep-v Grep|awk ' {print $} ' | Xargs Kill
This command will openoffice all processes and then wait a few minutes to see if OpenOffice is restarted:
Ps-ef|grep/opt/openoffice4/program/soffice
About Cron Service knowledge:
1. Type CRONTAB-E edit crontab service file
For example, the contents of the file are:
*/2 * * * */bin/sh/home/admin/deletefile.sh
Save the file and exit
2. See if the Crontab service under this user was created successfully with the CRONTAB-L command
3. Start the crontab service
General start-up services with service Crond start;
4. See if the service is already running
PS and Servicecrond status are available;
5. Crontab command
The Cron service provides the crontab command to set the Cron service, and here are some of the parameters and instructions for this command:
Crontab-u//Set a user's Cron service, which is usually required by the root user when executing this command
crontab-l//listing details of a user's cron service
crontab-r//Delete a cron service with no users
crontab-e//editing a user's cron service
For example, root to view your cron settings: Crontab-u root-l
Again, for example, Root wants to delete Fred's cron settings: Crontab-u fred-r
When editing the Cron service, the edited content has some formatting and conventions, input: Crontab-u root-e
Enter VI edit mode, the content of the edits must conform to the following format: */1 * * * * ls>>/tmp/ls.txt
Crond resident command for task scheduling
Crond is a command that Linux uses to execute programs on a regular basis. When the operating system is installed, the default is to start the
The Task Dispatch command. The Crond command periodically checks if there is any work to be done,
The work will be performed automatically.
6. crontab Command options:
-u Specifies a user
-l lists a user's task schedule
-R Delete a user's task
-e Edit a user's tasks
If you need to edit a user's timed execution tasks, such as WebLogic users ' scheduled execution tasks:
Crontab-u weblogic–e
Input: */1 * * * *ls >>/usr/tmp/ls.txt Save exit:
To delete a WebLogic task, use:
7. cron file Syntax:
Hour of the week order
0-59 0-23 1-31 1-12 0-6 Command (value range, 0 for Sunday One a row corresponds to a task)
Remember the meanings of several special symbols:
"*" represents a number in the range of values,
"/" stands for "every",
"-" represents a number to a number,
"," separate a few discrete numbers
Direct Write/etc/crontab file contents do not take effect.
Service Crond Reload/restart also does not take effect.
Query original because, the direct write crontab file, need to specify the execution user, and the above environment variables cannot be deleted.
Such as:
# Cat/etc/crontab
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root
home=/
*/1 * * * * Root date >/root/test.txt
If you do not specify a running user in a scheduled task, such as:
*/1 * * * * date >/root/test.txt
This command is not executed.
3. Service Restart 1/etc/init.d/crond Restart 2 service crond restart
Workaround for OpenOffice Process exception exit: