how to run .login and .profile file from cron (74 Views)
Reply
Frequent Advisor
MANISH PATEL_2
Posts: 56
Registered: ‎01-23-2007
Message 1 of 10 (74 Views)

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
Please use plain text.
Outstanding Contributor
Pete Randall
Posts: 16,205
Registered: ‎11-03-1996
Message 2 of 10 (74 Views)

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
Please use plain text.
Honored Contributor
Tim Nelson
Posts: 3,725
Registered: ‎06-01-2000
Message 3 of 10 (74 Views)

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.

Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 4 of 10 (74 Views)

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...
Please use plain text.
Honored Contributor
Peter Nikitka
Posts: 1,575
Registered: ‎02-10-2003
Message 5 of 10 (74 Views)

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"
Please use plain text.
Frequent Advisor
MANISH PATEL_2
Posts: 56
Registered: ‎01-23-2007
Message 6 of 10 (74 Views)

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
Please use plain text.
Honored Contributor
OldSchool
Posts: 3,372
Registered: ‎09-09-2004
Message 7 of 10 (74 Views)

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
Please use plain text.
Frequent Advisor
MANISH PATEL_2
Posts: 56
Registered: ‎01-23-2007
Message 8 of 10 (74 Views)

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
Please use plain text.
Frequent Advisor
MANISH PATEL_2
Posts: 56
Registered: ‎01-23-2007
Message 9 of 10 (74 Views)

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

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

Thanks
MP
Please use plain text.
Honored Contributor
Peter Nikitka
Posts: 1,575
Registered: ‎02-10-2003
Message 10 of 10 (74 Views)

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"
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation