Operating System - Linux
1748054 Members
4496 Online
108758 Solutions
New Discussion юеВ

how to run .login and .profile file from cron

 
MANISH PATEL_2
Frequent Advisor

how to run .login and .profile file from cron

Hi,
I want to execute .login file through cron. I want to setup a cron for xyz user. Is following command is correct...

00 2 * * * ./appl/temp/.login

I can run from user login and execute the following is ok.
/appl/temp>./.login

But the following i can not run, getting error.
/appl/temp>./appl/becca/.login
./appl/becca/.login: Command not found.

Pls let me know which is the correct command to setup in cron.

Thanks
mp
9 REPLIES 9
Pete Randall
Outstanding Contributor

Re: how to run .login and .profile file from cron

You need a space:

. /appl/becca/.login

That is dot space slash appl slash becca slash dot login


Pete

Pete
Tim Nelson
Honored Contributor

Re: how to run .login and .profile file from cron

Keep in mind that any environment variables are only as good as the current invocation of the shell.

Not sure what you really are trying to accomplish here. If it is the typicall "I need the users env for a script that is run" then you need to call the profile from within the script in the same manner and make sure to export all variables.

James R. Ferguson
Acclaimed Contributor

Re: how to run .login and .profile file from cron

Hi:

The environment provided by 'cron' to a task is quite sparsely defined. From the manpages for 'crontask' you will see that the PATH variable consists, by default, of only '/usr/bin' and '/usr/sbin' and your ${HOME} directory.

Any environmental variables you need must also be supplied by sourcing (reading) your login profile (a poor way); by sourcing a file of those variables (a good way); or by coding them in the script you run.

Since the typical login .profile has interactive, terminal-oriented commands like 'stty' and 'tset', processing your standard profile leads to "Not a typewriter" messages. Either modify your '.profile' to exclude these when it is not interactive:

if [ -t 0 ]; then
stty ...
fi

...or place your environmental variables in a file that can be sourced by both your .profile and any script that needs it:

. myenv

...Note the dot, followed by whitespace, followd by the filename. That is called 'sourcing' and causes the file named to be read into the current shell's environment without spawning a new shell.

Regards!

...JRF...
Peter Nikitka
Honored Contributor

Re: how to run .login and .profile file from cron

Hi,

files with the name '.login' are often used to set environment variables in CSH-like shells.
These commands won't work well in Bourne-like shells, even when calling the script with the correct syntax.
The cron configuration will (nearly 100%) start each crontab-entry in a posix-shell environment.
If you use tcsh - for example - you would have to use a command line like this:
0 2 * * * tcsh -c 'source xxx/.login; morecommands'

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
MANISH PATEL_2
Frequent Advisor

Re: how to run .login and .profile file from cron

Hi Pete

I tried from user login . /appl/temp/.login but i m getting following error.
Following PATH setup for user:-PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/appl/temp

/bin/.: Permission denied.

Regards
MP
OldSchool
Honored Contributor

Re: how to run .login and .profile file from cron

"Following PATH setup for user:-PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/appl/temp

/bin/.: Permission denied."

A) What shell is the used by the ID you tried?
-and-
B) What *exactly* is in the file /appl/temp/.login?

FWIW: /bin should be a link to /usr/bin anyway, so it hasn't any meaning in this context
MANISH PATEL_2
Frequent Advisor

Re: how to run .login and .profile file from cron

Hi,

i am using C shell and from .login it execute perl scripts.

Anyway i incorporate in sh and it execute from shell scripts.

Thanks
Manish
MANISH PATEL_2
Frequent Advisor

Re: how to run .login and .profile file from cron

Hi guys,
I incorporate the execute scripts in shell.
It work fine.

Thanks
MP
Peter Nikitka
Honored Contributor

Re: how to run .login and .profile file from cron

Hi,

your forum profile tells us:
I have assigned points to 19 of 71 responses to my questions.

Here is a link, describing how to submit points:
http://forums11.itrc.hp.com/service/forums/helptips.do?#33

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"