該問題找了好久...Orz

重點應該在Crontab執行SH檔案跟你直接登入root還是有些許差異,

重點在於【系統環境】的配置不同,找了許多文章都教導:

 1.使用絕對路徑。

   2.使用前先執行/etc/profile系統配置檔案。

而我遇到的問題是無法取得Java的環境設定造成執行失敗,所以解決方式就是在SH檔案的開頭加入。

#!/bin/ksh
source /etc/profile

 


 

烂笔头——crontab运行失败片面解决方案
http://hi.baidu.com/huangboxiang/item/4ee7a78c7c6ba318c2162753

用户登陆Linux操作系统的时候,"/etc/profile", "~/.bash_profile"等配置文件会被自动执行。执行过程是这样的:登陆Linux系统时,首先启动"/etc/profile",然后启动用户目录下的"~/.bash_profile",如果"~/.bash_login"和"~/.profile"文件存在的时候也会在执行"~/.bash_profile"后被依次调用。

-------------------------------------------

Crontab运行相关问题以及解决方法
http://blog.csdn.net/wireless_tech/article/details/6417996

脚本中所有的命令和工具使用绝对路径例如/usr/local/bin/mysql,或者在脚本前面执行一下profile文件:. /etc/profile即可

-------------------------------------------

Linux 討論版-快瘋了 crontab就是有問題
http://phorum.study-area.org/index.php?topic=23908.10;wap2

避免 env 的環境變數設定差異...
通常我如果要把 shell 丟在 cron 執行的話, 我都會把該使用者目錄底下的
.profile 執行一次, 因為通常都會因為 $PATH 設定的問題而導致執行出錯

-------------------------------------------

了解一下-shell的变量与执行
http://yahoon.blog.51cto.com/13184/412439

常见问题
如果我们在/etc/profile里面定义了JAVA_HOME,然后写了java的启动脚本,常常会发现直接执行脚本可以,但是放入到crontab里面就不行(因为crontab里面的是在non-login shell下执行的,不会读取/etc/profile文件,自然找不到$JAVA_HOME
这个时候crontab这么写
su - root  脚本

-------------------------------------------

crontab 的使用及注意事项
http://837244.blog.51cto.com/827244/1136679

2)脚本执行要用到java或其他环境变量时,通过source命令引入环境变量,如:
cat start_cbp.sh
#!/bin/sh
source /etc/profile
export RUN_CONF=/home/d139/conf/platform/cbp/cbp_jboss.conf
/usr/local/jboss-4.0.5/bin/run.sh -c mev &
3)当手动执行脚本OK,但是crontab死活不执行时。这时必须大胆怀疑是环境变量惹的祸,并可以尝试在crontab中直接引入环境变量解决问题。如:
0 * * * * . /etc/profile;/bin/sh /var/www/java/audit_no_count/bin/restart_audit.sh

-------------------------------------------

crontab是不认识profile的
http://www.cnblogs.com/SuperXJ/archive/2012/03/16/2399856.html

. /etc/profile
. ~/.bash_profile

 


 


设置Tomcat Jboss Oracle Mysql Linux自启动服务实例
http://just4java.iteye.com/blog/703290


Crontab 環境變數,這算是很重要的基本觀念,所以不能忘~~~
http://goodjoy1003.blogspot.tw/2010/04/crontab.html

 
Crontab与shell不得不说的故事
http://sillydong.com/mysa/myserver/crontab-shell-redirect.html

 
linux 自动重启tomcat 脚本
http://hi.baidu.com/sleinet/item/8d92155b8ae0d3cfd3e10c7a

 

arrow
arrow
    全站熱搜

    Nathan 發表在 痞客邦 留言(0) 人氣()