crontab environment help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers crontab environment help
# 1  
Old 09-30-2009
crontab environment help

Hi, I've read many many threads and I'm still having problems (yes i read https://www.unix.com/answers-frequent...n-crontab.html and it's suggested posts too).

My problem is with the $PWD, yes, that's the only causing problems so i have exported the PATH, I've checked it's exported, everything else runs but $PWD returns a null value so that part of the script can't run!
Code:
#!/bin/sh
printf "My path $PWD lalalala"

This is all the scrip does (it's a test from a much larger code that's failing in the PWD).
When I run on command runs fine, using cron it just prints "My path: lalalala"

I added: ". $HOME/local.profile" (without quotes) to the scrip that call this, and I print the env to make sure the PATH for my environment is the same as that of cron, and it is:

PATH=/usr/bin:/usr/ucb:/etc:.

I even changed the SHELL to bash in case it made any difference, it didnt.

Please someone give me more ideas why $PWD is not recognize in the script through cron!

Maybe it has to do with env printing a value for PWD and OLDPWD but cron's doesn't? How would I set PWD in cron's environment? I tried this in my profile:
PWD=$PWD
export PWD

when environment ran it gave a null PWD, same as in the scripts so.... this didn't work. =(

Last edited by malky; 09-30-2009 at 01:25 PM..
# 2  
Old 09-30-2009
Quote:
Originally Posted by malky
How would I set PWD in cron's environment?
Not exactly a setting but a workaround I'm using:

Code:
PWD=$( pwd )

# 3  
Old 09-30-2009
I'm thinking, in your script, cd to any directory, and the env will set PWD to that dir.
# 4  
Old 09-30-2009
Thanks for your response,
I added:

Code:
PWD=$( pwd )
export PWD

but i get from cron's report:
startup.sh: syntax error at line 9: `PWD=$' unexpected

---------- Post updated at 10:49 AM ---------- Previous update was at 10:45 AM ----------

Quote:
Originally Posted by varontron
I'm thinking, in your script, cd to any directory, and the env will set PWD to that dir.
Great Idea!


oh, I tried... then printed env inside scrip that's run by cron... PWD still not set and I'm still getting an empty value. =(

Any more ideas?


Lets make it more simple, im not even going to call my script, I'll just run this:
Code:
* * * * * printf "My path: $PWD lala"

I still get "My path: lala"

* * * * * = (set the time as you wish)

Last edited by malky; 09-30-2009 at 01:55 PM..
# 5  
Old 09-30-2009
Please state what Operating System and version you are using and whether this is a root cron or a user cron. It would also help to know if "/bin/sh" is a POSIX shell or something else like a Berkeley Shell.
# 6  
Old 09-30-2009
Code:
* * * * * PWD=`pwd` && printf "My path: $PWD lala"

# 7  
Old 09-30-2009
It's solaris 10.

How do I find out if it's a root or user cron? I cannot change it's cron.deny file or look at the logs without -su but i can definitelly add scripts as a user.

Quote:
if "/bin/sh" is a POSIX shell or something else like a Berkeley Shell.
How do I find that out?

Thanks all for your help, im really struggling with this.

---------- Post updated at 11:10 AM ---------- Previous update was at 11:03 AM ----------

Quote:
Originally Posted by vgersh99
Code:
* * * * * PWD=`pwd` && printf "My path: $PWD lala"

worked on crontab! but then it doesn't work when i use it in my script and i called the script using cron Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

environment variable in shell script called through crontab

Please help me on below.. https://www.unix.com/shell-programming-scripting/141533-retrieve-value-environment-variable-shell-script-called-crontab.html#post302442024 I'm still here. I can still see you! (0 Replies)
Discussion started by: jadoo_c2
0 Replies

2. Shell Programming and Scripting

Retrieve the value of environment variable in shell script which called from crontab

There are two files one is shell script (sample.sh) and another is configuration file (sampl_conf.cfg) configuration file contains one variable $FTP_HOME. the value of this variable vaires for user to user. If user is say jadoo then value is /home/jadoo/ftp/, for user1 - /home/user1/ftp. The... (0 Replies)
Discussion started by: jadoo_c2
0 Replies

3. Programming

Getting another process' environment

Suppose that I have an environment variable (call it "EVAR") that I set before running a process (call it "myproc"). "myproc" is run multiple times by multiple users and each may set "EVAR" differently. I.E.: UserA: export EVAR=v1 myproc UserB: export EVAR=v2 myproc Now "myproc" is... (3 Replies)
Discussion started by: DreamWarrior
3 Replies

4. Solaris

Environment variable

Hello, For the moment, my LC_ALL variable is set as "" by default. If I want to change this value, I do : export LC_ALL="en_fr" for example. That I want to know it's : how can I set by default this value ? I want to save it on my profile in order to get it when I open my session... :confused:... (2 Replies)
Discussion started by: MasterapocA
2 Replies

5. Shell Programming and Scripting

environment variable

Hi, I have to set bunch of variables and all other programs like make, perl will use them .. Here are my constraints and requirements ... The variables have to be set by executing a script that runs in c shell. I cannot source the script since people who use this script might be on... (8 Replies)
Discussion started by: sharanbr
8 Replies

6. Solaris

Environment help please

Hello all, I am a bit confused not only because I am new to Solaris but because when I run "env" I get a list of variables that are not in the user .profile. Where else can the account be getting environment variables from? Is there a .profile that applies to all accounts? Thank you in... (4 Replies)
Discussion started by: komputersman
4 Replies

7. UNIX for Advanced & Expert Users

Reset environment - ".. /etc/.environment dev_env"

I have been resently working on some ksh script. One of the line in the file writes: .. /etc/.environment dev_env I can not understand what this mean, all I know is .environment is unix system environment file. Is ".." a command? If some one can give me some clue where can I find information... (7 Replies)
Discussion started by: zzwu3591
7 Replies

8. Programming

environment variables

hi, I want to create a new EV(Environment Variable) through a c program and I done this thing through setenv() method. But the newly created EV is not permanent, i.e. when I exit from the program the EV also no longer lives. But I want to make it a permanent EV for the current user. Actually I... (6 Replies)
Discussion started by: sumsin
6 Replies

9. UNIX for Advanced & Expert Users

help on environment variable

what is the environment variable used for getting the <machine name> . hello $LOGNAME,welcome to <??> I want to print the machine name in the place of <??> Please help. (6 Replies)
Discussion started by: mehuldoshi
6 Replies

10. Programming

environment variables

Hi! How-to get the environment variables in GNU. getenv() only fetches the ones that you can find under export (not the ones under declare)... best regars .David (2 Replies)
Discussion started by: Esaia
2 Replies
Login or Register to Ask a Question