LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-20-2009, 02:22 AM   #1
vjayraghavan
LQ Newbie
 
Registered: Feb 2009
Posts: 15
Blog Entries: 1

Rep: Reputation: 0
Problem when invoking the values of variabled from different program


Hi,

I am facing some problems in invoking the variable from a different program and making it local to it...

i am using

. ./<program_name> ## my conf file which has all the variables

i have a function to download the files from FTP... The user name, Password and folder name to download the file from ftp location is given in the conf file... But i am not able to get the values from conf file and give it to the function...

Can any one help me on this regards...
 
Old 05-20-2009, 02:30 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Can you show what you are actually doing?

The following works (as expected):
Code:
$ cat tstcfg 
A="1"
B="FOO"
C="BAR"

$ cat test.tstcfg.sh
#!/bin/bash

. tstcfg

echo $A $B $C

$ ./test.tstcfg.sh
1 FOO BAR
 
Old 05-20-2009, 04:11 AM   #3
vjayraghavan
LQ Newbie
 
Registered: Feb 2009
Posts: 15

Original Poster
Blog Entries: 1

Rep: Reputation: 0
Code:
. ~/.bash_profile
. ~/vijayconf.sh


echo "$partner"  ### working 
echo "$ftp_username"  ### working 
echo " outside the function" 
echo "$partner $ftp_username $ftp_server" ### Not working

ctl_output_file=$partner_home/logs/bby_wh_import.log
echo $ctl_output_file
check_and_download()
{
       echo "$partner"  ### ### Not working
        echo "inside function $partner $datatype " ### Not working
        echo "Download $partner $datatype from the sftp server $ftp_server" ### Not working
        remote_dir=`echo $remote_dir | sed -e 's/^\///' -e 's/\/$//'` ### Not working
        scp $ftp_username@$ftp_server:$remote_dir/${file_name_pattern}* $partner_home/data/download ### Not working
}
i have pasted the code and i have also mentioned the working and now working part... I believe i am able to get the variable values in some point and in some point it is not working...
 
Old 05-20-2009, 04:28 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

This snippet is not enough to get an idea what it is you want to do:

1) Is it a script (no hashbang on the first line),
2) Why parse your profile,
3) vijayconf.sh seems to be a script, why parse it and not execute it,
4) The function (ctl_output_file) is not called in the snippet you posted,
5) $partner_home => this variable (partner_home) isn't mentioned/created anywhere (same for: datatype, remote_dir, ....).

Show more and tell us what it is you expect it to do.
 
Old 05-20-2009, 04:45 AM   #5
vjayraghavan
LQ Newbie
 
Registered: Feb 2009
Posts: 15

Original Poster
Blog Entries: 1

Rep: Reputation: 0
Is it a script (no hashbang on the first line) --- > i missed to copy that line
Why parse your profile, ---- > It has some variable exported which this program needs
vijayconf.sh seems to be a script, why parse it and not execute it, ---> it is a conf file which has value of $partner_home , and many variables


contents in vijayconf.sh
partner="BBYSKU"
datatype="WarehouseLocationFeed"
ftp_server="sftp"
ftp_username="bbyskudl"
#ftp_password=`getpw bbysku bbyskudl`
remote_dir=/whse/
file_name_pattern="bby_warehouse_import"
partner_home=$PARTNERS_HOME/bbysku
partner_id=106
### Setting for Database
#password=`getpw $DB_TNS_NAME $DB_USER_NAME`

I am trying to invoke these variable to the script which is calling it...

The same works fine in a different server... so i thought there might be some problem with the profile file so i removed even the line ". ~/.bash_profile"
Not sure what is the problem wiht this environment...
 
Old 05-20-2009, 05:06 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Quote:
Originally Posted by vjayraghavan View Post
Is it a script (no hashbang on the first line) --- > i missed to copy that line
Is it a bash/ksh/csh/??? script?

Quote:
Why parse your profile, ---- > It has some variable exported which this program needs
You only need to do that in special cases, normally your profile is parsed when logging in and the variables should be available to you (and any child). Why are you parsing it.

Quote:
vijayconf.sh seems to be a script, why parse it and not execute it, ---> it is a conf file which has value of $partner_home , and many variables
To keep files 'undestandable' I would suggest renaming it to vijayconf.cfg (.conf, .ini whatever your preference but it should reflect its purpose).

Quote:
partner_home=$PARTNERS_HOME/bbysku
Is PARTNERS_HOME set somewhere else? Otherwise this one would be NULL (empty).

You did not answer the question about how the function is called.

You mention that this seems to be working on another machine. What are the differences? (linux vs Unix, bash vs ksh etc).

Using set -x at the beginning of the script (after the hashbang) outputs all expanded/filled arguments (among other things), during the run of the script. I could give you a clue which step(s) do/don't work.
 
Old 05-21-2009, 05:05 AM   #7
vjayraghavan
LQ Newbie
 
Registered: Feb 2009
Posts: 15

Original Poster
Blog Entries: 1

Rep: Reputation: 0
it is a bash script...

$PARTNERS_HOME value is set in the .profile file...


The same script works in a different machine which has same configuration... I suspect some environment problems but no clue what it is ...

Any ways i have made the script to work by explicitly declaring the variables in the script and it seems to be working...

Thanks a lot for ur efforts...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Invoking MySql From the Prompt tego90 Linux - Newbie 4 04-09-2009 06:16 PM
invoking GNU debugger for C program cleopard Programming 2 05-01-2008 11:09 AM
bash script--variables have unexpected values on invoking mplayer stairwayoflight Programming 5 07-08-2007 11:17 AM
Problem invoking user mago Linux - General 4 03-29-2005 04:25 PM
Change prompt values from within a C++ program pshea Linux - Newbie 0 09-16-2003 11:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration