|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello all,
I want to call my users .profile in cron? I understand that i have to do it explicitly in crontab entry. How can we do it ? How can i write a simple script calling it? Thanks & Regards Abhijeet |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
. $HOME/.profile
-Mike |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
How is the .profile file comes into play when we run a scripts ?
How is the .profile file comes into play when we run a scripts ? |
|
#4
|
|||
|
|||
|
It doesn't... the .profile is read only by a login shell, not every time a shell script is run.
When you login, since your .profile is read, you have certain things set up for you- like your $PATH. If those things are in environment variables (that is, if they've been exported), then scripts will have access to those things. Again, a good example is the $PATH. However, when cron runs a script the .profile is not read. This causes problems when you write scripts because things work when you run them but not when cron runs them. So you need to always check your assumptions when doing shell programming... things like "What directory does the shell script think it's in?" and "What PATH does the shell script require?" -Mike |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Including .profile: an example
Hi Here is a line from my crontab: Code:
10 4 * * * . ~/.profile; ${SCRIPTS}/backup_mysql.sh >> ${BACKUPS_LOG}/${HOSTNAME}_mysql_v${VERS}.script.log 2>&1Assume each crontab command line generates a new shell. The ". ~/.profile;" command string: "dot space <...>", populates the environment variables for the new shell. The variables - in this case - are specific to the USER. They are called from the users home directory, etc. The ". ~/.profile; " command string must be on the same crontab line, separated with ";" - a semi-colon. Do the same for EACH crontab command line. Hope this is helpful! Regards GrahamB |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
For the scripts that I've written, I execute the .profile within the script - not in cron. hence, in the script ${SCRIPTS}/backup_mysql.sh, you would see ... Code:
#!/usr/bin/ksh
...
#- Ensure User Environment Set -#
. ${HOME}/.profile
...
[rest of script]Hope that's of some help. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Quote:
For them, you must use Code:
. $HOME/.profile Thus, in general, it is better to use $HOME in cronjobs rather than getting used to a metacharacter which is peculiar to non-bourne shells. Also, I would caution against using $HOME/.profile in any shell script, in any event. This is because the $HOME/.profile is for setting up your login profile. When you are running a script you are not logged in. Your scripting environment should be stable, secure, and knowable. Since my .profile is mine, it's liable to be messed with at any time. Also, if you're doing such things as database backups or some system-related function with your ID- or depending on resources affiliated with your ID- what happens when you leave your job? Make a nice happy, stable home for your shell scripts. It's good style, and some SA will thank you for it later... -Mike Schwager |
| Sponsored Links | ||
|
![]() |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can we call crontab -e into .profile? | ksrivani | UNIX for Advanced & Expert Users | 3 | 10-06-2011 10:41 AM |
| Call .profile in perl script | Pratik4891 | Shell Programming and Scripting | 2 | 09-30-2011 02:26 AM |
| how to run script? call other script? su to another user? make a cron? | instant000 | Shell Programming and Scripting | 15 | 11-23-2009 04:01 PM |
| Please Help: How to Call SSH Trust from Cron job. | suman82 | Shell Programming and Scripting | 4 | 12-15-2008 02:43 PM |
| cron .profile | Schoey | Solaris | 1 | 10-21-2005 06:37 AM |
|
|