How do write using variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do write using variables
# 1  
Old 05-04-2011
variables coding using INSTHOME

Hello Team,
I have the following line in a .sh file .That means if we add my file.sh file to crontab .The crontab will read the first line where the db2 profile is installed.Can some body help me how to recode this using a variable ?

That means the below path is static to a perticular machine.Incase if i run the same script on another machine the echo $INSTHOME will give another path.so i want to use variable instead of hard code path. can some body help me ?

Code:
#!/bin/ksh
. /db2/inst1/sqllib/db2profile

Later i tried

Code:
if [ -f $INSTHOME/sqllib/db2profile ]; then
    . $INSTHOME/sqllib/db2profile
fi

even this is not working any suggesions?

Last edited by rocking77; 05-04-2011 at 12:30 PM..
# 2  
Old 05-04-2011
What about something like this

Code:
## First line always states the shell you are using.
#!/bin/ksh

## Get the name of the machine.
MACHINE=$(uname -n)

## Set INSTHOME based on the machine.
case $MACHINE in
   'Jerry') INSTHOME="/db2/inst1"
            ;;
  'George') INSTHOME="/db2/inst2"
            ;;
             # Always code for an unexpected value.
         *) print "Unknown machine [$MACHINE]"
            exit 1
            ;;
esac

## If we are here then a machine was found so set the environment.
. $INSTHOME/sqllib/db2profile

## More commands follow...

# Always exit with a return code back to the shell.
exit 0

# 3  
Old 05-04-2011
Hi Gary,
Thanks for your reply.I tried this in my script .

Code:
if [[ -f $INSTHOME/sqllib/db2profile ]] ; then
    . $INSTHOME/sqllib/db2profile

instead of

Code:
. /db2/db9sr073/sqllib/db2profile

.

in my script the problem is the earlier code is not running when i use this file.sh in crontab.but if i run file.sh using ./file.sh its running perfectly.Any clue why the earlier code is not working when i use this and crontab it ?
# 4  
Old 05-04-2011
Where is INSTHOME being set?

I do not believe it is being set in the environment of the crontab-run version. crontab runs with the permission level of the id that created the job, but not their environment if I remember correctly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Interactive Python 3.5+ sys.stdout.write() AND sys.stderr.write() bug?

(Apologies for any typos.) OSX 10.12.3 AND Windows 10. This is for the serious Python experts on at least 3.5.x and above... In script format sys.stdout.write() AND sys.stderr.write() seems to work correctly. Have I found a serious bug in the interactive sys.stdout.write() AND... (2 Replies)
Discussion started by: wisecracker
2 Replies

2. Shell Programming and Scripting

Is it possible to write write multiple cronjobs in shellscript??

Hi All, I need the answer of below question? 1) How to write multiple cronjobs in shellscript? Is there any way or we cant write in shellscript... Regards, Priyanka (2 Replies)
Discussion started by: pspriyanka
2 Replies

3. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

5. Shell Programming and Scripting

How can I write variables to same line of a file?

I am trying to keep variables in a file. if I have all variables at the same time, I can write them all like below. echo $var1","$var2","$var3 But, these variables are being calculated at different times then they are lost so I want to keep them in a file seperated by "," . echo... (5 Replies)
Discussion started by: snr_silencer
5 Replies

6. Shell Programming and Scripting

Write string variables to file

I have the following: #! /bin/bash foo="bar" this="that" vars="foovar=$foo\n\ thisvar=$this\n" I want to write the following to a file: foovar="bar" thisvar="that" Then in another script, I pull this file, and loop through it: while read line; do eval $line done <... (3 Replies)
Discussion started by: Validatorian
3 Replies

7. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

8. Shell Programming and Scripting

how to write 2 variables while using read command

Hello All i have input files contains 2 values as following 20-Oct-09 Z59408009 20-Oct-09 Z59423060 and i am using the following script cat /home/or/input.txt | awk '{print $2}' >log count=0 while read line; do count=$(( count + 1 )) echo "UPDATE SAT_JRLTRT SET AVT='X' WHERE... (6 Replies)
Discussion started by: mogabr
6 Replies

9. Shell Programming and Scripting

Find all files with group read OR group write OR user write permission

I need to find all the files that have group Read or Write permission or files that have user write permission. This is what I have so far: find . -exec ls -l {} \; | awk '/-...rw..w./ {print $1 " " $3 " " $4 " " $9}' It shows me all files where group read = true, group write = true... (5 Replies)
Discussion started by: shunter63
5 Replies

10. Shell Programming and Scripting

Write system variables into file

Hi everyone, I was told, i my job, to do a script that creates the backup of all the files that are important to us. So i created the script, put it in the crontab and it works great. Now what i want is to write to a file what directories have being copied with date and time. How can i... (3 Replies)
Discussion started by: jorge.ferreira
3 Replies
Login or Register to Ask a Question