Linux (centos 6.5) calls java scripts and regularly executed script instances and configuration files for details, centosjava

Source: Internet
Author: User

Linux (centos 6.5) calls java scripts and regularly executed script instances and configuration files for details, centosjava
Linux (centos 6.5) calls java scripts and regularly executed script instances
1. Call the java program script (the Java environment has been set up by default)

1. jdk installation path/usr/jdk/jdk1.7 /......
2. java program path/usr/jdk
3. Class Name: Test. java (class name with main function)
4. Call a java Script. Note that the suffix of the script is. sh.
5. Script content:
(1 )#! /Bin/bash
//#! Special symbol. It indicates that the script is interpreted by the bash shell in the/bin directory and the interpreted content is sent to the kernel for execution.
(2) cd/usr/jdk
(3)/usr/jdk/jdk1.7/bin/javac Test. java
(4)/usr/jdk/jdk1.7/bin/java Test
6. Script Name: testshell. sh
7. Execute this script to compile the java program and explain how to execute the jvm machine code.

8. Execute the script command: sh testshell. sh


Ii. scheduled task execution

1. linux has a system-level scheduled task service named cron. The command in the terminal is crontab. You can use it to regularly execute scripts.

2. Write the crontab file for the scheduled task in the/etc/directory.

3. There are two open methods: user level and system level: crontab-e user level vim crontab system level.

4. There are two ways to open the task. crontab-l displays user-level scheduled tasks more/less/tail/head to view system-level tasks.

5. attributes defined in the crontab file:

SHELL =/bin/bash
PATH =/sbin:/bin:/usr/sbin:/usr/bin
MAILTO = root
HOME =/
(1) The SHELL variable specifies the shell to be used by the system. bash is used here.

(2) the PATH variable specifies the PATH for the system to execute commands.

(3) The crond task execution information specified by the MAILTO variable will be sent to the root user via email. If the value of the MAILTO variable is null, the task execution information will not be sent to the user.

(4) The HOME variable specifies the main directory used for executing commands or scripts.

6. scheduled task format: an instance in crontab. It is edited using vim, so it is system-level.
# For details see man 4 crontabs

# Example of job definition:
#. ---------------- Minute (0-59)
# |. ----------- Hour (0-23)
# |. ---------- Day of month (1-31)
# |. ------- Month (1-12) OR jan, feb, mar, apr...
# |. ---- Day of week (0-6) (Sunday = 0 or 7) OR sun, mon, tue, wed, thu, fri, sat
# |
# ***** User-name command to be executed
* *** Root sh/usr/jdk/testshell. sh

*/1 ***** root sh/usr/jdk/testshell. sh

Explanation: with the built-in crontab, we can clearly see the format of the scheduled task, so we will not mention it. The two tasks defined above are executed every minute, while the user is the root

7. The scheduled task is completed here, but it may not be executed successfully. The following describes the mistakes that cainiao like me will make frequently.

8. If no scheduled task is executed after definition, you can go to/var/spool/mail to view the corresponding logs. If an error is reported, it indicates that the script is written incorrectly, note that the path is the most likely error here, so you can try to write a full path when writing a script.

9. If no error is reported, the scheduled task is not executed. cron is a scheduled execution tool in linux and can run the job without manual intervention. Since Cron is a built-in service in Linux, but it does not automatically get up, you can use the following methods to start and close this service:

/Sbin/service crond start // start the service

/Sbin/service crond stop // close the service

/Sbin/service crond restart // restart the service

/Sbin/service crond reload // reload the configuration

10. You can also enable the service automatically when the system starts:

Add:

/Sbin/service crond start


11. Time Setting:

Minutes (0-59)

Hour (0-23)

Date (1-31)

Month (1-12)

Week (0-6) // 0 represents Sunday

In addition to numbers, there are also several special symbols: "*", "/", "-", * representing all numbers in the value range, "/" indicates the meaning of each, "*/5" indicates every five units, "-" indicates the number from a number to a number, "," separate several discrete numbers

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.