About Linux under crontab when the script executes, the value obtained is incorrect

Source: Internet
Author: User

This is because you need to create a timed task to determine the status of the SNMP service. The

is judged by the following code

tmp= '/etc/init.d/snmpd status ' snmpd_status = ' echo  $tmp  | grep -Eo  ' running '   ' if [  $snmpd _status =  ' Running " ] then    snmpd_status=" Running "else    snmpd_ Status= "Stop" fiecho  $snmpd _status 

Note: The system is Red Hat 5.7 and 6.5

The

Now SNMPD service is in normal operation.

I did this by manually executing the script, and the result was running

But as long as I put it in crontab, it was a stop

.

Later, I printed every variable in the script to see, found that the language environment for the crontab operation is Chinese.

But my export is obviously in English.

I didn't think of it at first, because I did it manually and crontab used the root account


After I joined the export in front of the script Leng= "en_US", after the script execution ring language is set to English, the result of execution is normal.


For the speech variables in the environment variables, do not know why it appears in such cases, there is time to study under. If any of the great gods know, please point twos

This article is from the "mi-can have" blog, be sure to keep this source http://michankong.blog.51cto.com/1464983/1894694

About Linux under crontab when the script executes, the value obtained is incorrect

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.