- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- User environment for cron jobs
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2006 01:15 AM
тАО03-10-2006 01:15 AM
User environment for cron jobs
How do I control the environment when I run cron jobs, in other words what startup file is getting sourced in? $HOME/.login? I doubt $HOME/.profile is getting sourced in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2006 01:17 AM
тАО03-10-2006 01:17 AM
Re: User environment for cron jobs
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2006 01:19 AM
тАО03-10-2006 01:19 AM
Re: User environment for cron jobs
Answer: none
Cron runs with a minimal evironment. Check the man page for crontab if you want to know the details. Your best bet is to source a profile that will set the PATH and whatever environment variables you will need. You could source /etc/profile or $HOME/.profile or some other profile that combines these to give you what you need.
You could also explicitly define the variables and PATH in your cron job - whichever works for you.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2006 01:20 AM
тАО03-10-2006 01:20 AM
Re: User environment for cron jobs
. $HOME/.profile
But you have to set HOME variable.
Schimidt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2006 01:22 AM
тАО03-10-2006 01:22 AM
Re: User environment for cron jobs
"cron supplies a default environment for every shell, defining:
HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry."
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2006 01:28 AM
тАО03-10-2006 01:28 AM
Re: User environment for cron jobs
The 'cron' environment is quite sparse as the manpages for 'crontab' will divulge. For example, your PATH consists only of '/usr/bin' and '/usr/sbin'.
The most appropriate way, in my opinion, to define commonly used environmental variables is to collect them in a standalone file that can be sourced (read) *either* by your '$HOME/.profile' as it is processed during login() or by scripts that you run and/or cron.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2006 01:40 AM
тАО03-10-2006 01:40 AM
Re: User environment for cron jobs
"cron" doesnt take any ENV variables. You need to set them individually,
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2006 02:42 AM
тАО03-10-2006 02:42 AM
Re: User environment for cron jobs
The least evil approach I have found is to setup a separate file to set and export any needed variables, e.g. /usr/local/bin/myenv.sh, and have the user's .profile AND your cron'ed script source this file via the . (dot) operator.
This sourced file must not contain any return or exit statements as that will have the effect of terminating the process.