crontab environment help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers crontab environment help
# 8  
Old 09-30-2009
This doesn't work from cron?
Code:
#!/bin/sh
PWD=`pwd`
printf "My path $PWD lalalala"

# 9  
Old 09-30-2009
Your code works but what I need is:

crontab
Code:
0 * * * * sh /scriptpath/etc/myscript.sh

myscript.sh:
Quote:
#!/bin/sh
. $HOME/.profile
PWD=`pwd`
/mypath/etc/scriptNeeded2Run
This can be done in crontab I don't mind as long as $PWD will run on scriptNeeded2Run. I just added this script so I could upload my profile and any other environment setting needed as suggested in other forums!

scriptNeeded2Run:
Quote:
#!/bin/sh
printf "My path $PWD lalalala"

I cannot modify this script because it's not mine, and it works on command line so no code can be added here, it has to be in myscript.sh or crontab.


To resume, I run sh ./myscript.sh from command line i get "My path /path/i/am/right/now lalalala"
If it runs in cron i get "My path lalalala"

Thanks!

Last edited by malky; 09-30-2009 at 02:09 PM..
# 10  
Old 09-30-2009
any particular reason why you do this ??:
Code:
sh /mypath/etc/scriptNeeded2Run

instead of this:
Code:
/mypath/etc/scriptNeeded2Run

# 11  
Old 09-30-2009
Quote:
Originally Posted by vgersh99
any particular reason why you do this ??:
Code:
sh /mypath/etc/scriptNeeded2Run

instead of this:
Code:
/mypath/etc/scriptNeeded2Run


I realized I copied it wrong to the forum, I corrected it right after. There's no sh. Smilie

thanks
# 12  
Old 09-30-2009
problem solved?
# 13  
Old 09-30-2009
No, PWD doesn't get carried.

There must be a setting that I can set either in my .profile, crontab or my sh script so that scriptNeeded2Run can recognize $PWD inside!

How does people run scripts that use $PWD that are run through cron! Smilie

---------- Post updated at 01:45 PM ---------- Previous update was at 01:31 PM ----------

vgersh99 thanks so much!
I used your PWD=`pwd` idea and added the export to make it work, thanks for the light.

For the people that needs this solution in the future:

Code:
#!/bin/sh 
. $HOME/.profile
PWD=`pwd` 
export PWD
/mypath/etc/scriptNeeded2Run

I added the export PWD in my sh code! when i did this in the profile it didint work.

Thanks so so much all. solved!
 
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