JAVA计划任务失败,请大佬赐教

60次阅读

共计 4034 个字符,预计需要花费 11 分钟才能阅读完成。

nohup java -jar x.jar >/dev/null 2>&1 &
这串代码放宝塔的计划任务启动失败,但是 SSH 登录终端执行代码就是正常的,请大佬赐教,谢谢!

HOH 发表于 2022-9-4 04:04
path of x.jar

cd www
nohup java -jar path of x.jar >/dev/null 2>&1 &

cd www
path of x.jar
nohup java -jar x.jar >/dev/null 2>&1 &
都失败啊 path of x.jar 楼上正解,写全路径就行了 java -jar x.jar >/var/log/why.log 2>&1
看 why 告诉你

Akewa 发表于 2022-9-4 11:21
java -jar x.jar >/var/log/why.log 2>&1
看 why 告诉你

. ____ _ __ _ _
/\ / ___’_ __ _ _(_)_ ____ _
(()___ | ‘_ | ‘_| | ‘_ / _` |
\/___)| |_)| | | | | || (_| |) ) ) )
‘|____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.3.RELEASE)
2022-09-04 04:09:21.605INFO 807875 — [main] com.gkc : Starting TrxApplication v1.0 with PID 807875 (/www/x.jar started by root in /www)
2022-09-04 04:09:21.611INFO 807875 — [main] com.gkc : No active profile set, falling back to default profiles: default
2022-09-04 04:09:21.793INFO 807875 — [main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]255316f2: startup date [Sun Sep 04 04:09:21 EDT 2022]; root of context hierarchy
2022-09-04 04:09:24.390INFO 807875 — [main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 ‘javax.inject.Inject’ annotation found and supported for autowiring
2022-09-04 04:09:25.432INFO 807875 — [main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 1111 (http)
2022-09-04 04:09:25.452INFO 807875 — [main] o.apache.catalina.core.StandardService : Starting service Tomcat
2022-09-04 04:09:25.453INFO 807875 — [main] org.apache.catalina.core.StandardEngine: Starting Servlet Engine: Apache Tomcat/8.5.14
2022-09-04 04:09:25.601INFO 807875 — [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-09-04 04:09:25.601INFO 807875 — [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3822 ms
2022-09-04 04:09:25.799INFO 807875 — [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean: Mapping servlet: ‘dispatcherServlet’ to [/]
2022-09-04 04:09:25.806INFO 807875 — [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘characterEncodingFilter’ to: [/*]
2022-09-04 04:09:25.807INFO 807875 — [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘hiddenHttpMethodFilter’ to: [/*]
2022-09-04 04:09:25.807INFO 807875 — [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘httpPutFormContentFilter’ to: [/*]
2022-09-04 04:09:25.807INFO 807875 — [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘requestContextFilter’ to: [/*]
2022-09-04 04:09:26.297INFO 807875 — [main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot[email protected]255316f2: startup date [Sun Sep 04 04:09:21 EDT 2022]; root of context hierarchy 这不是启动了吗

js 攻城狮 发表于 2022-9-4 16:19
这不是启动了吗

没有启动,日志是我用 ssh 登录终端执行代码获取的 nohup java -jar -Dspring.profiles.active=prod /file/xxx.jar >>/file/xxx.log 2>&1 & 要把错误日志发出来,有可能是环境变量的原因。试试 jdk 和 jar 包都写绝对路径

小米八宝茶 发表于 2022-9-4 16:35
nohup java -jar -Dspring.profiles.active=prod /file/xxx.jar >>/file/xxx.log 2>&1 &

还是一样的,ssh 登录终端可以使用,宝塔的计划任务就无法使用

iiss 发表于 2022-9-4 16:44
要把错误日志发出来,有可能是环境变量的原因。

Usage:
kill [options] <pid> […]
Options:
<pid> […] send signal to every <pid> listed
-<signal>, -s, –signal <signal>
specify the <signal> to be sent
-q, –queue <value> integer value to be sent with the signal
-l, –list=[<signal>]list all signal names, or convert one to a name
-L, –table list all signal names in a nice table
-h, –help display this help and exit
-V, –versionoutput version information and exit
For more details see kill(1).
—————————————————————————-
★[2022-09-04 04:59:26] Successful
—————————————————————————- 定时任务直接调应该没有环境,写到脚本里再定时调用

mlc 发表于 2022-9-4 17:27
定时任务直接调应该没有环境,写到脚本里再定时调用

大佬,只能发一下怎么写吗?用宝塔的菜鸡,不懂啊不是宝塔跑不起来吗
我是让你把
nohup java -jar x.jar >/var/log/why.log 2>&1 &
加到宝塔任务里,让宝塔执行一次
再看 why 里日志

发财 发表于 2022-9-4 17:01
Usage:
kill [options][…]

可以联系我签名 tg 我帮你看看,你这个不是错误日志,你给的不对。

Akewa 发表于 2022-9-4 17:40
不是宝塔跑不起来吗
我是让你把

寄,楼主看不懂什么叫控制变量法

发财 发表于 2022-9-4 17:34
大佬,只能发一下怎么写吗?用宝塔的菜鸡,不懂啊

参考一下这个就可以了,后面 cron 定时表达式只要后面的命令写在宝塔的定时任务里面就行了
https://blog.csdn.net/u011418530/article/details/83104193 用绝对路径避免环境变量的问题

云缨 发表于 2022-9-4 19:23
用绝对路径避免环境变量的问题

是的,解决了,非常感谢各位大佬解惑!!!

正文完
 0