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
Here is a line from my crontab:
Assume 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.
Here is a line from my crontab:
Assume each crontab command line generates a new shell. The ". ~/.profile;" command string: "dot space <...>", populates the environment variables for the new shell. ...
Caveat Programmer: . ~/.profile MAY work- for example, if you are in Linux, where sh is the same as bash. However, for Solaris and other UNICES, sh is the bourne shell and will not recognize the ~ (tilde) metacharacter.
For them, you must use
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
i have this line of code on my script
#!/bin/sh
#enable the environment variable thru profile
. .profile
when i run the script it was unable to find the .profile
sh ChgPwd.sh
ChgPwd.sh: line 4: .: .profile: file not found
the file .profile exists
ls -altr .profile... (2 Replies)
Hello all,
Please my shell is ksh. I created .profile such that users can pick environments they want to use:
echo Select your Environment!!
echo " 1. Nigeria DEV"
echo " 2. UEMOA DEV"
echo " 3. CEMOA DEV"
echo "Make your choice : \c"
read choice
if
then
...
fi
if
then (6 Replies)
My first post evidently did not materialize so I posted it again:
Runnning a cron job every 5 mins to send data files to a state facility.
My original cron entry at worked fine:
01,06,11,16,21,26,31,36,41,46,51,56 * * * * /home/sftpuser/stateinoc-from-appname.ksh
Somewhere I have a... (1 Reply)
Hi All,
I have a doubt that can we call under whatever scripts we mention in crontab -e into .profile .
Because every weekend my server is going to restart so, my doubt whether crontab -e will automatically run my scripts or manually we have to save the crontab -e again?
If that crontab... (3 Replies)
Hello Gurus
Can anyone please let me know how to call .profle file in perl script
When I am calling the .profile file its giving error
Shall I create unix script which has .profile command and call perl script internally (2 Replies)
Good morning. I am searching for "how-to"'s for some particular questions:
1. How to write a script in HP-UX 11.
2. How to schedule a script.
3. How to "call" scripts from the original script.
4. How to su to another user from within a script.
This is the basics of what the... (15 Replies)
Hello
I really wonder what's trap in etc/profile and in each user .profile.
I try to google for it but I think I have no luck. Mostly hit is SNMP traps which I think it is not the same thing.
I want to know ...
1. What's a "trap 2 3" means and are there any other value I can set... (4 Replies)
Hi All,
I am tring to excute a SSH trust command from a script which is invoked by crontab.
Details:
Crontab file contains the following line:
15 00 * * * /users/dummy_user/dummy_script1.sh
dummy_script1.sh contains the following line:
SSH -1 server_2... (4 Replies)
hi , i added ls -F to .profile. and i need to do ./.profile for the effect to take effect BUT i didnt and YET the next day when i came to work and log in, the changes took effect. i am on aix.
please explain..
thanks (4 Replies)