Help - Setting variables equal to data from another file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help - Setting variables equal to data from another file
# 1  
Old 03-05-2007
Help - Setting variables equal to data from another file

Relatively new poster but long time reader. I tried searching all threads for similar situations with mine but I've had no luck with some of the solutions.

I have a script (script.ksh) that is getting information from an Oracle DB and spooling it into a text file (log.txt). I would then like to assign the information from log.txt to variables in the script.ksh

Example...

script.ksh
Code:
#!/bin/ksh

#
#  CONNECTING TO ORACLE DATABASE
#*************************************

sqlplus -s user/pass@somedatabase << eof
set pagesize 0;
set heading off;

spool somepath/log.txt;

select WORKFLOW, FOLDER, SERVER, USER_NAME, PASS from JOB_TABLE where JOB_NAME = 'test';

spool off;

EXIT
eof

This is creating log.txt - which contains the following...
Code:
test_name
test_folder
test_server
test_user
test_password

Now this is where I'm getting lost. When I want to save the info from log.txt to variables in script.ksh - I'm getting empty fields

This is how I'm doing it in script.ksh...
Code:
WF_NAME= `tail -1 /somepath/log.txt| awk '{print $1}'`
FDR_NAME= `tail -1 /somepath/log.txt| awk '{print $2}'`
SRV_NAME= `tail -1 /somepath/log.txt| awk '{print $3}'`
USR_NAME= `tail -1 /somepath/log.txt| awk '{print $4}'`
PASS= `tail -1 /somepath/log.txt| awk '{print $5}'`

When I echo out each variable - I get blanks. Any Ideas? I'm assuming I'm doing something wrong with the "tail" - I don't think I even need it... just the way someone suggested for me to do it but I believe it isn't the correct method.

The goal is to get WF_NAME = test_name, FDR_NAME = test_folder, etc. so I can pass these as parameters to a different script.

Probably something dumb but I can't seem to figure it out. Thanks in advance for the help.
# 2  
Old 03-05-2007
Quick Update:

I think I narrowed down the error. I didn't realize that the tail flag was actually the number 1 .... "tail -1" - doh!

The actual content of the log.txt contains 2 empty lines at the end.

So each variable was getting filled with blank info, due to the "-1" part. I need to either:

1 - put everything in one line in log.txt
2 - fix the tail commands to read the correct lines

Any recommendations as to which would be more efficient ?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a file and setting to variables.

greetings all, I have a task right now that is somewhat stumping me, and I am not sure what the best approach is to take it. I have a text file that will contain something similar to the following: first1, other1 first2, other2 first3, other3 first4, other4 I have to generate an... (14 Replies)
Discussion started by: jeffs42885
14 Replies

2. Shell Programming and Scripting

Setting environment variables from a file :

Hi, I have around 10 environment variables in my shell script. i want to set this all in a file and just call that file in my shell script. How can i do that ? Please help. TIA! (6 Replies)
Discussion started by: qwertyu
6 Replies

3. Shell Programming and Scripting

Setting environment variables in Cron file

Hi, In Cron file i'm using username and password hard-coded and now i wann to use environmental veraiables in cron file. But Could you please guide me how to use these environmental variables in cron file ? Thanks, Shyamu.A (4 Replies)
Discussion started by: shyamu544
4 Replies

4. Shell Programming and Scripting

awk - setting fs to equal any single character

Hi Does anyone know how to set any character as the field separator with awk/nawk on a solaris 10 box. I have tried using /./ regex but this doesnt work either and im out of ideas. thanks (7 Replies)
Discussion started by: chronics
7 Replies

5. Shell Programming and Scripting

setting and displaying variables

Hello, I need a little help. 1. Edit /etc/profile so that all users are greeted upon login. 2. For the root account, set the prompt to something like "Danger!! root is doing stuff in \w", preferably in a bright color such as red or pink or in reverse video mode. Thanks for help. (4 Replies)
Discussion started by: zhshqzyc
4 Replies

6. Shell Programming and Scripting

How to read a file and assign variables to data?

Hi, I need a simple csh script to read a file containing data like this Buy Transactions : 175 Sell Transactions : 212 Server: sepo2 i want to read both field and its value and assign variables to each.. (2 Replies)
Discussion started by: pravsripad
2 Replies

7. Shell Programming and Scripting

Setting array equal to command response

normally when i type: condor_q | tail -1 command line returns: 0 jobs; 0 idle, 0 running, 0 held I want use the number in front of 'running' in a series of equality tests to submit more jobs when my queue gets low. Someone showed me how to do it a few days ago by setting an array equal to... (4 Replies)
Discussion started by: pattywac
4 Replies

8. UNIX for Dummies Questions & Answers

Setting up variables

Hi all, I have a shell script that sets up the environment for an application running on UNIX - ksh. This script is run using: . ./script_name XX where XX is a parameter. I want to run it from another shell script but when I do it I don't get the envornment variables set up and the prompt... (3 Replies)
Discussion started by: solar_ext
3 Replies

9. UNIX for Advanced & Expert Users

setting some variables

i have a file .NAMEexport MY_NAME=JOE when i do this at the command prompt #. .NAME $echo MY_NAME $JOEi created a script called Run.sh . .NAME At the command prompt i did #sh Run.sh #echo $MY_NAMEit returns nothing. What have i missed out? (7 Replies)
Discussion started by: new2ss
7 Replies

10. Shell Programming and Scripting

Passing data from file to variables for script

Hello all! After searching through numerous helpful posts on these forums I am still having an issue with a task I am trying to accomplish. I am trying to take data from an input file, store the contents as variables, and use the variables in the script. The input file (input.txt) is... (2 Replies)
Discussion started by: screwed718
2 Replies
Login or Register to Ask a Question