相必你已经搜了很多文章才搜到我这边文章,也知道了如果crontab执行程序有自己的环境变量,想要执行自己程序,要找到程序对应的环境变量。
crontab -l
结果如下:
LD_LIBRARY_PATH=/usr/sap/PRD/HDB10/exe/krb5/lib/krb5/plugins/preauth:/usr/sap/PRD/HDB10/exe/krb5/lib:/usr/sap/PRD/HDB10/exe:/usr/sap/PRD/HDB10/exe/Python/lib:/usr/sap/PRD/HDB10/exe/filter:/usr/sap/PRD/HDB10/exe/dat_bin_dir:/usr/sap/PRD/HDB10/exe/plugins/afl:/usr/sap/PRD/HDB10/exe/plugins/lcapps:/usr/sap/PRD/HDB10/exe/plugins/repository:/usr/sap/PRD/HDB10/exe/plugins/epmmds:/usr/sap/PRD/SYS/global/hdb/federation:/usr/sap/PRD/SYS/global/hdb/plugins/3rd_party_libs
LS_COLORS=no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.xz=00;31:*.avi=01;35:*.bmp=01;35:*.dl=01;35:*.fli=01;35:*.gif=01;35:*.gl=01;35:*.jpg=01;35:*.jpeg=01;35:*.mkv=01;35:*.mng=01;35:*.mov=01;35:*.mp4=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.svg=01;35:*.tga=01;35:*.tif=01;35:*.webm=01;35:*.webp=01;35:*.wmv=01;35:*.xbm=01;35:*.xcf=01;35:*.xpm=01;35:*.aiff=00;32:*.ape=00;32:*.au=00;32:*.flac=00;32:*.m4a=00;32:*.mid=00;32:*.mp3=00;32:*.mpc=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:*.wma=00;32:*.wv=00;32:
HOSTTYPE=x86_64
PYTHONHOME=/usr/sap/PRD/HDB10/exe/Python
LESSCLOSE=lessclose.sh %s %s
XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
DIR_EXECUTABLE=/usr/sap/PRD/HDB10/exe
LANG=en_US.UTF-8
WINDOWMANAGER=/usr/bin/gnome
LESS=-M -I -R
HOSTNAME=jcerphanadb1
OLDPWD=/usr/sap/PRD/HDB10
CSHEDIT=emacs
TINSTANCE=10
GPG_TTY=/dev/pts/6
AUDIODRIVER=pulseaudio
LESS_ADVANCED_PREPROCESSOR=no
COLORTERM=1
ALSA_CONFIG_PATH=/etc/alsa-pulse.conf
MACHTYPE=x86_64-suse-linux
QEMU_AUDIO_DRV=pa
MINICOM=-c on
SAP_RETRIEVAL_PATH=/usr/sap/PRD/HDB10/jcerphanadb1
QT_SYSTEM_DIR=/usr/share/desktop-data
OSTYPE=linux
USER=prdadm
PAGER=less
ASAN_SYMBOLIZER_PATH=/usr/sap/PRD/HDB10/exe/llvm-symbolizer
MORE=-sl
ASAN_OPTIONS=alloc_dealloc_mismatch=0:log_path=/usr/sap/PRD/HDB10/jcerphanadb1/trace/AddressSanitizer_Crashdump:handle_segv=0:allow_user_segv_handler=1:abort_on_error=1:check_initialization_order=1:detect_leaks=0:detect_odr_violation=0:use_sigaltstack=0:allocator_may_return_null=1
PWD=/usr/sap/PRD/HDB10
HOME=/usr/sap/PRD/home
HOST=jcerphanadb1
DIR_SYSEXE=/usr/sap/PRD/SYS/exe/hdb
XNLSPATH=/usr/share/X11/nls
SAPSYSTEMNAME=PRD
XDG_DATA_DIRS=/usr/share
SECUDIR=/usr/sap/PRD/HDB10/jcerphanadb1/sec
PROFILEREAD=true
TSAN_OPTIONS=exitcode=0:log_path=/usr/sap/PRD/HDB10/jcerphanadb1/trace/ThreadSanitizer_Report
DAT_BIN_DIR=/usr/sap/PRD/HDB10/exe/dat_bin_dir
MAIL=/var/spool/mail/prdadm
LESSKEY=/etc/lesskey.bin
TERM=xterm
SHELL=/bin/sh
LS_OPTIONS=-N --color=tty -T 0
XCURSOR_THEME=DMZ
PYTHONSTARTUP=/etc/pythonstart
SHLVL=1
DIR_INSTANCE=/usr/sap/PRD/HDB10
PYTHONPATH=/usr/sap/PRD/SYS/global/hdb/custom/python_support:/usr/sap/PRD/HDB10/exe/python_support:/usr/sap/PRD/HDB10/jcerphanadb1:/usr/sap/PRD/HDB10/exe:/usr/sap/PRD/HDB10/exe/testscripts:/usr/sap/PRD/HDB10/exe/Python/lib/python2.7
G_FILENAME_ENCODING=@locale,UTF-8,ISO-8859-15,CP1252
MANPATH=/usr/local/man:/usr/share/man
LD_BIND_NOW=1
LOGNAME=prdadm
XDG_CONFIG_DIRS=/etc/xdg
PATH=/usr/sap/PRD/HDB10/exe/krb5/bin:/usr/sap/PRD/HDB10/exe/krb5/sbin:/usr/sap/PRD/HDB10/jcerphanadb1:/usr/sap/PRD/HDB10:/usr/sap/PRD/HDB10/exe:/usr/sap/PRD/HDB10/exe/mdc:/usr/sap/PRD/HDB10/exe/Python/bin:/usr/sap/PRD/HDB10/exe/dat_bin_dir:/usr/sap/PRD/home:/usr/sap/PRD/home/bin:/usr/local/bin:/usr/bin:/bin
SDL_AUDIODRIVER=pulse
G_BROKEN_FILENAMES=1
HISTSIZE=1000
CPU=x86_64
OMP_NUM_THREADS=1
LESSOPEN=lessopen.sh %s
_=/usr/bin/env
* * * * * /usr/sap/PRD/HDB10/exe/Python/bin/python /usr/sap/PRD/HDB10/cmd_rst_v1.py > /dev/null 2>&1
注意点:
- 定时任务的命令路径要写全
- 如何查找非root用户的环境变量?比如有AIX,SUSE系统的机器:env
- 非root用户创建定时任务,先创建一个文件,cronTmp,填写需要的内容,执行crontab cronTmp