bash脚本无法运行Java程序cron作业 [英] Bash Script unable to run Java Program as cron job
问题描述
我想从一个bash脚本运行一个.class文件使用crontab每1分钟。我得到的错误无法找到或加载主类Cron_Read_Send_CapacityData_To_Graphite。我已经在我的机器上设置环境变量。
如果我从它的工作原理fine.Note终端运行bash脚本的bash脚本和Java类文件是在同一文件夹
脚本:
$猫Run_Cron_Read_Send_CapacityData_To_Graphite.sh
#!/斌/庆典java的Cron_Read_Send_CapacityData_To_Graphite>> /home/marshell/graphite_cronjobs/Cron_Read_Send_CapacityData_To_Graphite.log
cron项:
$ crontab -e命令* / 1 * * * * /home/marshell/graphite_cronjobs/Run_Cron_Read_Send_CapacityData_To_Graphite.sh>> /home/marshell/graphite_cronjobs/debug_cronjob.log 2 - ;&放大器; 1
错误:
错误:无法找到或加载主类Cron_Read_Send_CapacityData_To_Graphite
您错误消息表明您的类路径设置不正确的脚本找到 Cron_Read_Send_CapacityData_To_Graphite.class
,我会使用类似 -
CP = /家庭/马歇尔/ graphite_cronjobs#类路径使用
LF = $ CP / Cron_Read_Send_CapacityData_To_Graphite.log#日志文件
java命令$ CP Cron_Read_Send_CapacityData_To_Graphite>> $ LF
I am trying to run a .class file from a bash script every 1 minute using the crontab. I get the error Could not find or load main class Cron_Read_Send_CapacityData_To_Graphite. I have already set environment variable on my machine.
If i run the bash script from the terminal it works fine.Note the bash script and the java class file are in the same folder
Script:
$ cat Run_Cron_Read_Send_CapacityData_To_Graphite.sh
#!/bin/bash
java Cron_Read_Send_CapacityData_To_Graphite >> /home/marshell/graphite_cronjobs/Cron_Read_Send_CapacityData_To_Graphite.log
Cron entry:
$ crontab -e
*/1 * * * * /home/marshell/graphite_cronjobs/Run_Cron_Read_Send_CapacityData_To_Graphite.sh >> /home/marshell/graphite_cronjobs/debug_cronjob.log 2>&1
Error:
Error: Could not find or load main class Cron_Read_Send_CapacityData_To_Graphite
You error message indicates that your classpath isn't set correctly for the script to find Cron_Read_Send_CapacityData_To_Graphite.class
, I would use something like -
CP=/home/marshell/graphite_cronjobs # The classpath to use
LF=$CP/Cron_Read_Send_CapacityData_To_Graphite.log # the log file
java -cp $CP Cron_Read_Send_CapacityData_To_Graphite >> $LF
这篇关于bash脚本无法运行Java程序cron作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!