Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem if the script of crontab in linux is not executed

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to solve the problem of non-execution of crontab scripts in linux, the content is concise and easy to understand, and it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. When calling oracle's sqlplus, sqlldr and other command tools, the full path must be written in order to execute successfully in crontab, otherwise, although manual operation is normal, an exception occurs as soon as it is configured on crontab.

2. When you run the shell script manually, you can use the sh command; but in cron, you must not use sh to execute the command, but to list the shell script files directly.

3. When calling crontab, if it is useful to the database, it is best to write out the relevant environment variables of the database.

4. To schedule in crontab, it is best to write absolute paths to all files referenced in shell scripts.

5. If it is a script for an ORACLE database, be sure to pay attention to the environment variables, such as

PATH=$PATH:$HOME/bin

Export PATH

Export TMP=/tmp

Export TMPDIR=/tmp

Export ORACLE_BASE=/oracle/app

Export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1

Export ORACLE_SID=racdb1

Export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH

Export NLS_LANG= "SIMPLIFIED CHINESE_CHINA.ZHS16GBK"

6. Check whether the crond process is normal.

/ etc/init.d/crond status (it seems that the centos7 version does not have this command)

/ etc/init.d/crond start

Service rsyslog status

Ps-elf | grep crond

7. How to determine whether crontab is executed can be found in this log / var/log/cron.

8. If it is executed under the root user, the environment variable can be set to add these two lines

. / etc/profile

. ~ / .bash_profile

9. If it is the startup of the grails process

Nohup grails prod run-app-Dserver.port=xxxx-- non-interactive 2 > & 1 > nohup.out &

For the script to be executed successfully, more than N environment variables have been added

Here we add java-related environment variables for grails.

#! / bin/bash

# set environment variables

# root user environment variables

. / etc/profile

. ~ / .bash_profile

# java environment variable

JAVA_HOME=/home/app/jdk1.7.0_71

JAVA_OPTS= "- Xmx1024m-XX:MaxPermSize=512M"

GRAILS_HOME=/home/app/grails-2.3.11

MAVEN_HOME=/home/app/apache-maven-3.0.5

Export JAVA_HOME JAVA_OPTS GRAILS_HOME MAVEN_HOME

PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$GRAILS_HOME/bin:$MAVEN_HOME/bin

Export PATH

# find the process ID of 9898

Process_id1=$ (echo $(ps-ef | grep server.port=9898 | grep-v grep | awk'{print $2}'))

Process_id2= `ps-ef | grep rule-service-api1 | grep-v grep | grep-v'/ home/app/rule-service-api1/restart_9898.sh' | awk'{print $2}'`

Count=$ (echo $(ps-ef | grep server.port=9898 | grep-v grep | awk'{print $2}'| wc-l)

# determine whether the process exists and restart the process

If [$count-eq 0]

Then

Cd / home/app/rule-service-api1/

Sh / home/app/rule-service-api1/startup-rule.sh > / opt/restart9898_1.log 2 > & 1

Sleep 10

Echo 'start successful' > > / opt/restart9898_1.log

Date > > / opt/restart9898_1.log

Else

Kill-9 $process_id1 $process_id2

Sleep 10

Cd / home/app/rule-service-api1/

Sh / home/app/rule-service-api1/startup-rule.sh > / opt/restart9898_1.log 2 > & 1

Sleep 10

Echo 'kill and restart successful' > > / opt/restart9898_1.log

Date > > / opt/restart9898_1.log

Fi

Encounter / etc/rc.local this boot self-boot, but write the command in it does not execute what to do

Note:

Ll / etc/rc.local

[root@test ~] # ll / etc/rc.local

Lrwxrwxrwx. 1 root root 13 Oct 23 2014 / etc/rc.local-> rc.d/rc.local

Found that this is a linked file.

[root@test ~] # ll / etc/rc.d/rc.local

-rw-r--r-- 1 root root 696 Oct 8 11:16 / etc/rc.d/rc.local

After checking, I found that the permission is 644, and there is no permission to execute. That's why.

Just give it permission.

Chmod 755 / etc/rc.d/rc.local

The above content is how to solve the problem if the script of crontab in linux is not executed. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report