Visit Our UNIX and Linux User Community


Passing info from other file into command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Passing info from other file into command
# 1  
Old 08-13-2009
Passing info from other file into command

I created file called "tape_name" which contains

tape_mon_A="TAPE_MON_A"
tape_tue_A="TAPE_TUE_A"
tape_wed_A="TAPE_WED_A"
tape_thr_A="TAPE_THR_A"
tape_mon_B="TAPE_MON_B"
tape_tue_B="TAPE_TUE_B"
tape_wed_B="TAPE_WED_B"
tape_thr_B="TAPE_THR_B"


I created test script as follow

#!/bin/sh

TAPE_LOC="location/of/the/above/file"
. /$TAPE_LOC/tape_name

echo "$tape_mon_A"

echo "$tape_tue_A"


when I run above script it returnes

TAPE_MON_A
TAPE_TUE_A

=============

Question is I don't want to hard code omnib command with tape name since it changes frequently.

my regular tape_name hardcoded commands run without any problem

sudo -u root /usr/bin/rsh domain.server.com "/opt/omni/bin/omnib -datalist TUE_TAPE-TST -mode full -load high

but when I changed TUE_TAPE-TST to $TAPE_BACKUP variable the command is not working.


Is there way to make TUE_TAPE-TST to accept variable parameter as I tried on test script?


thank you
# 2  
Old 08-14-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

*****************************************************

You don't want to hardcode, that's ok.
But wouldn't it be more helpful if you'd just check which day today is ie. with the Unix week day like:
Code:
date +%w
5

where it's output number is read as following
Code:
1 = monday
2 = tuesday
3 = wednesday
4 = thursday
5 = friday
6 = saturday
0 = sunday

You could check which day it is and then decide in a case construct for example which tape to use.

Quote:
but when I changed TUE_TAPE-TST to $TAPE_BACKUP variable the command is not working.
Why should it work? In your excerpts I can't see any definition of $TAPE_BACKUP.

The whole thing could be automated, including your sudo and backup commands. As said, I would try to get the current date 1st and then decide by this which tape to use.
# 3  
Old 08-14-2009
When I run following command
Code:
#!/bin/sh

TAPE_LIST="usr/local/bin/archbakTST/BACKUP_TAPES"
. /$TAPE_LIST

echo "sudo -u root /usr/bin/rsh remote.server.com /opt/omni/bin/omnib -datalist "$tape_test_TEST" -mode full -lo
ad high"

Return is
Code:
sudo -u root /usr/bin/rsh remote.server.com /opt/omni/bin/omnib -datalist  -mode full -load high

and is missing
Code:
sudo -u root /usr/bin/rsh remote.server.com /opt/omni/bin/omnib -datalist [missing parameter here] -mode full -load high

and $tape_test_TEST is from following file which contains one line of datalist called "TESTDB3-TEST"

BACKUP_TAPES:
Code:
tape_test_TEST="TESTDB3-TEST"


Last edited by zaxxon; 08-17-2009 at 06:11 AM.. Reason: some more CODE tags
# 4  
Old 08-17-2009
Not sure why it is not working. Try if a very simple example works and might want to use different #shebang with bash or ksh just to make sure:

Code:
$> cat parm
VAR=123
$> cat mach.ksh
#!/usr/bin/ksh

. ./parm
echo $VAR
$> ./mach.ksh
123

# 5  
Old 08-17-2009
Quote:
Originally Posted by zaxxon
Not sure why it is not working. Try if a very simple example works and might want to use different #shebang with bash or ksh just to make sure:

Code:
$> cat parm
VAR=123
$> cat mach.ksh
#!/usr/bin/ksh

. ./parm
echo $VAR
$> ./mach.ksh
123


Thank you! I found the mistakes on my script. Smilie
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #940
Difficulty: Medium
Ping was not included in 4.3BSD.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Creating file and passing argument to a command

Hi All, I am having command to run which will take argument as input file. Right now we are creating the input file by cat and executing the command ftptransfer -i input file cat >input file file1 file2 cntrl +d Is there a way I can do that in a single command like ... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

2. Shell Programming and Scripting

Passing Shell variable from file to another command

Hi all, I have a file looks like AAAA 111 BBBB 222 CCCC 333 need to pass variable value like var1=AAAA and var2=111 to another command for three times with next values. stuck over here cat file | while read line do export var1=`awk '{print $1}'` echo $var1 export var2=`cat file... (3 Replies)
Discussion started by: rakeshtomar82
3 Replies

3. Shell Programming and Scripting

Help with Passing the Output of grep to sed command - to find and replace a string in a file.

I have a file example.txt as follows :SomeTextGoesHere $$TODAY_DT=20140818 $$TODAY_DT=20140818 $$TODAY_DT=20140818I need to automatically update the date (20140818) in the above file, by getting the new date as argument, using a shell script. (It would even be better if I could pass... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

4. Shell Programming and Scripting

Create a file from ls -l command and append additional info to results

I need to be able to take the results from ls -l command and modify the output as follows: I will run ls -l *.mak My results will be aa.mak bb.mak cc.mak I then need to take those results and create a file that has the following info: dsjj/ubin/aa dsjj/ubin/bb dsjj/ubin/cc ... (3 Replies)
Discussion started by: jclanc8
3 Replies

5. UNIX for Dummies Questions & Answers

passing command arguments from a file?

Hi Im trying to run zip shell command from an Oracle job, but this has limitations. This should take a few of explanaition,.. Oracle allows me to execute a command and then I can set up a fixed number of arguments. Ex: (summarizing in something like..): JOB DEFINITION job_name: test... (4 Replies)
Discussion started by: vegatripy
4 Replies

6. Shell Programming and Scripting

Event logging to file and display to console | tee command is not able to log all info.

My intention is to log the output to a file as well as it should be displayed on the console > I have used tee ( tee -a ${filename} ) command for this purpose. This is working as expected for first few outputs, after some event loggin nothing is gettting logged in to the file but It is displaying... (3 Replies)
Discussion started by: sanoop
3 Replies

7. UNIX for Dummies Questions & Answers

passing command output from one command to the next command in cshell

HI Guys, I hope you are well. I am trying to write a script that gets executed every time i open a shell (cshell). I have two questions about that 1) I need to enter these commands $ echo $DISPLAY $ setenv $DISPLAY output_of_echo_$display_command How can i write a... (2 Replies)
Discussion started by: kaaliakahn
2 Replies

8. Shell Programming and Scripting

Splitting a file in to multiple files and passing each individual file to a command

I have an input file with contents like: MainFile.dat: 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 ... (4 Replies)
Discussion started by: rkrish
4 Replies

9. Shell Programming and Scripting

AT command parameter passing to php file

I have a bash script which utilizes a random function and then runs a file at now plus a random time. The problem is, that the php file requires a parameter after it eg: phpfile.php?code=123245b3 When i put in the file including the full path, with the at command, it will run, but not with... (1 Reply)
Discussion started by: thruxmore
1 Replies

10. UNIX for Dummies Questions & Answers

scripting: multiple values from file passing to command

one of my colleagues has this question. he has a command, C_CMD which accepts 4 variables, $1 $2 $3 $4 he wants to load up a file with multiple rows, one row per set of variables and then iteratively execute the command based on the content of the file. example: at the command line you'd... (5 Replies)
Discussion started by: LisaS
5 Replies

Featured Tech Videos