Monday, March 17, 2014

Environment for Cron Jobs

I never remember the environment variables that are set for "cron" jobs?  So I created a cron job on each of our platforms with the "set" command.

Unfortunately, this post is of limited usefulness.  Your system administrator can override the defaults, which would make my findings inaccurate for you.  And it is possible that some of the variables shown below already represent our local administrator's overrides.  Also, different versions of the OSes and of Bash will affect the symbols.  But it's a start.  :-)

I've highlighted the PATH since that is my most-often desired information.

Solaris

HOME=(account home dir)
IFS= 
LOGNAME=(account name)
MAILCHECK=600
OPTIND=1
PATH=/usr/bin:
SHELL=(account login shell)
TZ=(system timezone)

HP-UX

ERRNO=10
FCEDIT=/usr/bin/ed
HOME=(account home dir)
IFS=' 
'
LINENO=36
LOGNAME=(account name)
MAILCHECK=600
OLDPWD=(account home dir)
OPTARG
OPTIND=1
PATH=/usr/bin:/usr/sbin:.
PPID=(parent process ID)
PS2='> '
PS3='#? '
PS4='+ '
PWD=(account home dir)
RANDOM=(some random number)
SECONDS=0
SHELL=(account login shell)
TMOUT=0
TZ=(system timezone)
_=';'

I'm surprised to see "." in PATH.  I've always been taught that having "." in your path is dangerous, although most of the danger comes from having it early in your path (if you are "cd"ed into somebody else's directory, they might have an executable named "ls" which does an "rm -rf $HOME").

Linux

BASH=/bin/sh
BASHOPTS=cmdhist:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_LINENO=([0]="0")
BASH_SOURCE=([0]="(command)")
BASH_VERSINFO=([0]="4" [1]="1" [2]="2" [3]="1" [4]="release" [5]="x86_64-redhat-linux-gnu")
BASH_VERSION='4.1.2(1)-release'
DIRSTACK=()
EUID=(account effective UID)
GROUPS=()
HOME=(account home dir)
HOSTNAME=(system host name)
HOSTTYPE=x86_64
IFS=' 
'
LOGNAME=(account name)
MACHTYPE=x86_64-redhat-linux-gnu
OLDPWD=(account home dir)
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/bin:/bin
PIPESTATUS=([0]="0")
POSIXLY_CORRECT=y
PPID=(parent process ID)
PS4='+ '
PWD=(account home dir)
SHELL=(account login shell)
SHELLOPTS=braceexpand:hashall:interactive-comments:posix
SHLVL=2
TERM=dumb
UID=(account UID)
USER=(account name)
_=

I suspect if a different login shell were chosen, that a lot of symbols, expecially "BASH_*", would not be there.

AIX

AUTHSTATE=compat
ERRNO=10
FCEDIT=/usr/bin/ed
HOME=(account home dir)
IFS=' 
'
LANG=en_US
LC__FASTMSG=true
LINENO=36
LOCPATH=/usr/lib/nls/loc
LOGIN=(account name)
LOGNAME=(account name)
MAILCHECK=600
NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat
ODMDIR=/etc/objrepos
OLDPWD=(account home dir)
OPTIND=1
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java14/jre/bin:/usr/java14/bin
PPID=(parent process ID)
PS2='> '
PS3='#? '
PS4='+ '
PWD=(account home dir)
RANDOM=(some random number)
SECONDS=0
SHELL=/bin/bash
TERM=dumb
TMOUT=0
TZ=(system timezone)
USER=(account name)
_=';'

At first, I thought that the PATH was being loaded from a .bashrc or something, but the PATH shown does not match the account's .bashrc, .profile, etc.  I wonder if perhaps the system admin overrode the default.

FreeBSD

HOME=(account home dir)
IFS=' 
'
LOGNAME=(account name)
OPTIND=1
PATH=/usr/bin:/bin
PPID=(parent process ID)
PS1='$ '
PS2='> '
PS4='+ '
SHELL=(account login shell)
USER=(account name)

MacOS

BASH=/bin/sh
BASH_ARGC=()
BASH_ARGV=()
BASH_EXECUTION_STRING=
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="2" [2]="48" [3]="1" [4]="release" [5]="x86_64-apple-darwin10.0")
BASH_VERSION='3.2.48(1)-release'
DIRSTACK=()
EUID=(account effective UID)
GROUPS=()
HOME=(account home dir)
HOSTNAME=(system host name)
HOSTTYPE=x86_64
IFS=' 
'
LOGNAME=(account name)
MACHTYPE=x86_64-apple-darwin10.0
OPTERR=1
OPTIND=1
OSTYPE=darwin10.0
PATH=/usr/bin:/bin
POSIXLY_CORRECT=y
PPID=(parent process ID)
PS4='+ '
PWD=(account home dir)
SHELL=(account login shell)
SHELLOPTS=braceexpand:hashall:interactive-comments:posix
SHLVL=1
TERM=dumb
UID=(account UID)
USER=(account name)
_=/bin/sh

I suspect if a different login shell were chosen, that a lot of symbols, expecially "BASH_*", would not be there.