Setting up env variable in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Setting up env variable in ksh
# 1  
Old 03-08-2013
Setting up env variable in ksh

I am facing a very strange issue. I have script in ksh with #!/bin/ksh as shebang.

This script has function which sets the env variable before running other functions of the script. by
Code:
set_up_env()
{
  CONFIG_FILE="/opt/app/tools/deepmarking/latestVersion/script/UploadEnv"
  if [ -f ${CONFIG_FILE} ]
  then
    #Source the environment

   . ${CONFIG_FILE}
          else
    err_exit "ERROR: Config file doesnot exist"
  fi

 }

And the shell I am running this script is csh. But for some unknown reason, the env variable declared on the config file are not getting set properly and hence the purpose of the script is not achieved.
Sample Error:
Code:
: not foundksh: /opt/app/tools/deepmarking/latestVersion/script/UploadEnv[8]:
: not foundksh: /opt/app/tools/deepmarking/latestVersion/script/UploadEnv[29]:
: not foundksh: /opt/app/tools/deepmarking/latestVersion/script/UploadEnv[31]:
: not foundksh: /opt/app/tools/deepmarking/latestVersion/script/UploadEnv[35]:

But if i declare all these variables present on UploadEnv in the same script at the start. This works with out any issues.

A sample UploadEnv file
Code:
export SCRIPT_HOME="/opt/app/tools/deepmarking/latestVersion"
export LOG_DIR=${SCRIPT_HOME}/log
export DATA_DIR=${SCRIPT_HOME}/data
export SCRIPT_DIR=${SCRIPT_HOME}/script

Any help would be much appreciated.
# 2  
Old 03-08-2013
this is the rigidness of csh..try developing CSH compatible statements in your sourced file or make them ready for CSH during run-time

Code:
awk '/export/ { gsub(/export/,"setnev",$0); gsub(/=/," ",$0 ); print  > "TempUploadVars" }' UploadEnv

and then source the TempUploadVars
# 3  
Old 03-08-2013
Code:
. ./TempUploadVars

I am sourcing it like above.

But getting error as below now.

Code:
./TempUploadVars[1]: setnev: not found


Last edited by Scrutinizer; 03-08-2013 at 04:34 AM.. Reason: code tags
# 4  
Old 03-08-2013
please use source command in CSH..
# 5  
Old 03-08-2013
The request is on ksh, not csh, as far as I can read.

export should not be a problem in ksh according to the man pages.
What exactly do you have in lines 8, 29, 31, and 35 in script uploadenv?
# 6  
Old 03-11-2013
UploadEnv file

Code:
#!/usr/bin/ksh
########################################################
# Configuration variables for the Upload process
########################################################
export TODAY=`date +%Y%m%d`  ## YYYYMMDD
export TIME=`date +%H%M%S`   ## HHMMSS
export month=`date +"%Y%m"`
export lmonth=`date +"%Y%m" -d last-month`

export MAIL_TO="email@example.com"
export SCRIPT_HOME=/home/user/deepmarking
export LOG_DIR=${SCRIPT_HOME}/log
export DATA_DIR=${SCRIPT_HOME}/data
export SCRIPT_DIR=${SCRIPT_HOME}/script
export BACKUP_DIR=${SCRIPT_HOME}/data/backup
export DB_ITNAPP_R_USER=itnapp
export DB_ITNRO_E_PASSWD="aswQrtQU3YnQrdXA="
export DB_ITNRO_D_KEY="K3UFQN215bTZBN1MwZVA="
export DB_ITNAPP_R_SID=nothing
export LOGFILE=${LOG_DIR}/Job.log
export FTPSERVER=ftpserver.example.com
export FTP_DATA_DIR=/tmp/deepmarking/data
export FTPUSER=ftpuser
export FTP_E_PASSWD="VFpybHRzTmFDSzF4aGVjVDMUY1NHJoOTc="
export FTP_D_KEY="ZnBpNTZIlF1SkZkVlJZRElVQWI0WDg="
export PGPPATH=/opt/pgp/bin
export JAVAPATH=/opt/java/jdk1.6.0_24/bin
export JAR_FILE=${SCRIPT_DIR}/endcrypt-dbcp-jar-with-dependencies.jar
export OLDFILEDAYS=10

export FILE=${lmonth}01

export FTP_LOG_FILE=${LOG_DIR}/ftp_files_$TODAY\_$TIME.log

# 7  
Old 03-11-2013
Oh, you prefer leaving the line counting up to us. Where is line 35?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Setting ENV variables in PERL

I have perl script and in the first line we are invoking .sh script to set ENV variables. e..g eval '. $envfile; exec $PERL -S $0 "$@"' I want to change some of the env variables while the program is running and I am settging it like this .. $ENV{ORACLE_HOME}=trim($oraclehome);... (1 Reply)
Discussion started by: talashil
1 Replies

2. Web Development

Deny from env=env-variable Does not work

(Above from Apache docs). On my system, using: SetEnvIf User-Agent Mozilla IsBad=1 Order allow,deny Allow from all Deny from env=IsBad ...I see that environment variable is set (using phpinfo()) but the page is still served. No errors in the Apache logs. (1 Reply)
Discussion started by: gnurob
1 Replies

3. Shell Programming and Scripting

Setting a variable in a while loop (.ksh script)

Hello Everyone, I'm still trying to grasp many concepts in .ksh scripting, one of them being variables inside loops. My problem is the following: * I'm trying to set a variable inside a while read loop to reuse it outside of said loop. My lines are the following :... (13 Replies)
Discussion started by: jimmy75_13
13 Replies

4. Shell Programming and Scripting

Setting Variable in TCL to be understood by KSH Shell

Hi , I am having one TCL TK script , I am setting some variables in the GUI TK interface set DI 1 set MODELS_PATH /a/d/path but I want to make ksh shell understand the variables when I am running TK script I tried to do like this set a but it is not working ... (1 Reply)
Discussion started by: kshitij
1 Replies

5. UNIX for Dummies Questions & Answers

Setting env variables using script

Hi, I wrote two small scripts to set env variables in a shell. java_env.csh #!/bin/csh -fn setenv JAVA_HOME '/scratch/software/jdk1.5.0_11' setenv PATH $PATH':'$JAVA_HOME'/bin' and run it using csh ./java_env.csh But the env variables are not set. I tried running each line on the... (5 Replies)
Discussion started by: NoviceAmod
5 Replies

6. Shell Programming and Scripting

setting ksh environmental variable

Hi, I have problem setting up environmental variables. The idea is to start with main.ksh script that will run setting.ksh, and in side of it I'll set up variables. Please take a look at my code, and help me to find my mistake. Thanks, Mila Main.ksh look like this: #!/usr/bin/ksh #... (2 Replies)
Discussion started by: mefquik
2 Replies

7. Red Hat

Help with csh env setting in Fedora 8

Hi there, How can I change bash to csh when starting a terminal, and set some aliases for csh? I can't find such files like .cshrc in my home directory. Thanks a lot (1 Reply)
Discussion started by: dustinwang2003
1 Replies

8. AIX

edit env. setting

hi eveybody, i m trying to set acl using acledit command in AIX box but wat im gettung is 3002-100 acledit: EDITOR environment variable not set can anyone help me out how 2 set editor.................... thanks in advance (4 Replies)
Discussion started by: rrlog
4 Replies

9. Shell Programming and Scripting

Some env setting is causing the script not to work ?

Not sure what has changed in the Unix environment. The following script which was working is now not working. #!/usr/bin/ksh # ----------------------------------------------------------------------------- # File: monitor_db.sh # #... (1 Reply)
Discussion started by: uuser
1 Replies

10. Solaris

setting env

I am trying to set up my compiler, but when I go to look for gcc it not found but I get a message that stayed (/usr/oasys/bin) and when I go into the dir to set my env the following is type cp : cannot creat //pref/.environ: no such file or directory and I input ./setenv PATH=... (3 Replies)
Discussion started by: alsande
3 Replies
Login or Register to Ask a Question