Operating System - HP-UX
1820072 Members
3212 Online
109608 Solutions
New Discussion юеВ

export .profile to crontab

 
SOLVED
Go to solution
Mats Andersson_2
Occasional Contributor

export .profile to crontab

Hi, I'm looking for information about how I can export a users .profile to the crontabfile to get the right env. when running a cron job. Man pages says
"Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry."

But no example or syntax.

Thanks in advance.
/Mats A
4 REPLIES 4
Steve Steel
Honored Contributor
Solution

Re: export .profile to crontab

Hi


In begin of script

. .profile


The . and space stops it forking and keeps details at this level


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Fred Ruffet
Honored Contributor

Re: export .profile to crontab

You can either run all jobs in root's crontab, using "su - user -c job" to ensure sourcing of user's profile, or write scripts that source profile and run comands and then put this jobs in user's cron.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Mark Grant
Honored Contributor

Re: export .profile to crontab

It is usually better not to do this as users may edit the .profile themselves and fill it full of things that might break cron. Generally, people create another file that sets all the environment variables and they source that in their crontab with the following syntax

00 10 * * * . /home/myvariables && runscript

Notice the ".". This executes the file in the current shell so you don't need to export things though you can do if you want.

If you really want to source the .profile then change the path "/home/myvariables" to "/home/user/.profile"
Never preceed any demonstration with anything more predictive than "watch this"
Mats Andersson_2
Occasional Contributor

Re: export .profile to crontab

Thank's everyboby for quick answers

/Mats A