Creating a file inside a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a file inside a script
# 8  
Old 03-21-2006
This is the script:


DEFINE_ENV_VAR()
{
. /usr/dacscan/bin/DSCANenv
LOG=/dacscan/words/shdsl_mrp_verify_eqpt
DEFINE_ENV_VAR()
{
. /usr/dacscan/bin/DSCANenv
LOG=/dacscan/words/shdsl_mrp_verify_eqpt
ORACLE_HOME=/opt/oracle
ORACLE_SID=S
export ORACLE_HOME
export ORACLE_SID
TDATE=`date "+%m%d%y"$$`
DEFINE_ENV_VAR()
{
. /usr/dacscan/bin/DSCANenv
LOG=/dacscan/words/shdsl_mrp_verify_eqpt
ORACLE_HOME=/opt/oracle
ORACLE_SID=S
export ORACLE_HOME
export ORACLE_SID
TDATE=`date "+%m%d%y"$$`
LOGFILE=$log.$TDATE
}
user=`echo $LOGNAME`
if [ $user != dacscan ]
then
echo "Please login as 'dacscan' to run this tool" > $LOGFILE
exit 1
else
echo "U r a valid user and now the check for single instance is going on" | tee -a $LOGFILE
echo "U r user validation is successful"
fi

if [ ! -f /tmp/shdsl_mrp_verify_eqpt.tmp ]
then
ps -ef | grep shdsl_mrp_verify_eqpt.sh | awk '{print $8}' > /tmp/shdsl_mrp_verify_eqpt.tmp
else
echo "Another instance of the tool is already running. Only one instance of the tool can be run at a given point of time" | tee -a $LOGFILE
echo "Cannot run the tool as already another instance of the tool is running"
exit
fi

Create_Proc()
{
create=`sqlplus -s dacscan/mnc <<!
set serveroutput on;
start shdsl_mrp_verify_eqpt.sql;
!`
if [[ $(echo $create | grep "ORA-") != "" ]]
then
echo "Error occured while creating the procedure. Check the Activity log file for further details" | tee -a $LOGFILE
rm /tmp/shdsl_mrp_verify_eqpt.tmp
exit 1
fi
}

Run_Proc()
{
status=`sqlplus -s dacscan/mnc <<!
set serveroutput on;
spool shdsl_mrp_verify_eqpt;
exec EQPT_VERIFY;
spool off;
!`
if (($?!=0))
then
echo "Unable to connect to oracle for running/executing the procedure" |tee -a $LOGFILE
rm /tmp/shdsl_mrp_verify_eqpt.tmp
exit 1
elif [[ $(echo $status | grep "ORA-") != "" ]]
then
echo "Error occured while executing the procedure" | tee -a $LOGFILE
rm /tmp/shdsl_mrp_verify_eqpt.tmp
exit 1
fi
}
rm /tmp/shdsl_mrp_verify_eqpt.tmp
DEFINE_ENV_VAR
Create_Proc
Run_Proc

Now tell me what do I have to do.

Thanks in advance
# 9  
Old 03-21-2006
Quote:
Originally Posted by sendhilmani
This is the script:


DEFINE_ENV_VAR()
{
. /usr/dacscan/bin/DSCANenv
LOG=/dacscan/words/shdsl_mrp_verify_eqpt
DEFINE_ENV_VAR()
{
. /usr/dacscan/bin/DSCANenv
LOG=/dacscan/words/shdsl_mrp_verify_eqpt
ORACLE_HOME=/opt/oracle
ORACLE_SID=S
export ORACLE_HOME
export ORACLE_SID
TDATE=`date "+%m%d%y"$$`
DEFINE_ENV_VAR()
{
. /usr/dacscan/bin/DSCANenv
LOG=/dacscan/words/shdsl_mrp_verify_eqpt
ORACLE_HOME=/opt/oracle
ORACLE_SID=S
export ORACLE_HOME
export ORACLE_SID
TDATE=`date "+%m%d%y"$$`
LOGFILE=$log.$TDATE
}
I assume your script starts like this and not as shown above.

Code:
DEFINE_ENV_VAR()
{
. /usr/dacscan/bin/DSCANenv
LOG=/dacscan/words/shdsl_mrp_verify_eqpt
ORACLE_HOME=/opt/oracle
ORACLE_SID=S
export ORACLE_HOME
export ORACLE_SID
TDATE=`date "+%m%d%y"$$`
LOGFILE=$log.$TDATE
}
user=`echo $LOGNAME`
if [ $user != dacscan ]
then
echo "Please login as 'dacscan' to run this tool" > $LOGFILE
exit 1
else
echo "U r a valid user and now the check for single instance is going on" | tee -a $LOGFILE
echo "U r user validation is successful"
fi

if [ ! -f /tmp/shdsl_mrp_verify_eqpt.tmp ]
then
ps -ef | grep shdsl_mrp_verify_eqpt.sh | awk '{print $8}' > /tmp/shdsl_mrp_verify_eqpt.tmp
else
echo "Another instance of the tool is already running. Only one instance of the tool can be run at a given point of time" | tee -a $LOGFILE
echo "Cannot run the tool as already another instance of the tool is running"
exit
fi

Create_Proc()
{
create=`sqlplus -s dacscan/mnc <<!
set serveroutput on;
start shdsl_mrp_verify_eqpt.sql;
!`
if [[ $(echo $create | grep "ORA-") != "" ]]
then
echo "Error occured while creating the procedure. Check the Activity log file for further details" | tee -a $LOGFILE
rm /tmp/shdsl_mrp_verify_eqpt.tmp
exit 1
fi
}

Run_Proc()
{
status=`sqlplus -s dacscan/mnc <<!
set serveroutput on;
spool shdsl_mrp_verify_eqpt;
exec EQPT_VERIFY;
spool off;
!`
if (($?!=0))
then
echo "Unable to connect to oracle for running/executing the procedure" |tee -a $LOGFILE
rm /tmp/shdsl_mrp_verify_eqpt.tmp
exit 1
elif [[ $(echo $status | grep "ORA-") != "" ]]
then
echo "Error occured while executing the procedure" | tee -a $LOGFILE
rm /tmp/shdsl_mrp_verify_eqpt.tmp
exit 1
fi
}
rm /tmp/shdsl_mrp_verify_eqpt.tmp
DEFINE_ENV_VAR
Create_Proc
Run_Proc

Please put your code within code tags for easy reading.

Last edited by vino; 03-21-2006 at 08:09 AM..
# 10  
Old 03-21-2006
Yeah,
you are right. Actually I made a mistake while pasting it here. But I just want to know where am I going wrong as the file doesnt get created.
# 11  
Old 03-21-2006
These line

Code:
echo "Please login as 'dacscan' to run this tool" > $LOGFILE
exit 1
else
echo "U r a valid user and now the check for single instance is going on" | tee -a $LOGFILE

will never go into $LOGFILE. Because, they appear before the invocation of DEFINE_ENV_VAR. $LOGFILE doesnt have a name till DEFINE_ENV_VAR is called.

Last edited by vino; 03-21-2006 at 08:25 AM..
# 12  
Old 03-21-2006
Exactly. Just now I changed it and now its working fine. Thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating new file inside a for loop

Hi, I have list of files present in a folder. I want to search for a particular keyword sequentially and create a file which will be later used by some other program. Input files: $ ls a.dsx b.dsx c.dsx Dataline_.txt Dataline.txt loop.sh $ cat *.dsx help tyiis global for i in... (4 Replies)
Discussion started by: mac4rfree
4 Replies

2. Shell Programming and Scripting

Script to validate dates inside a file

Hi All, Looking forward a script with below requirement.Please let me know if any pointers. - there is a file which contains date - script will go inside the file and validate date is T-1 and for Friday T-3 - Send email with status -Shell is Ksh (2 Replies)
Discussion started by: dattatraya
2 Replies

3. Shell Programming and Scripting

Running .sh file inside a shell script

Hello, You might help a newbie like me, I am trying to run a .sh inside my shell script. After running that I need to execute below commands. Here's how my scripts looks like. Hope you can help: #!/bin/sh cd $ORACLE_HOME/owb/bin/unix ./OMBPlus.sh ---> goes to OMB+> directory cd... (10 Replies)
Discussion started by: aderamos12
10 Replies

4. Shell Programming and Scripting

Creating loops inside a file and extracting and loading data

Help needed (1 Reply)
Discussion started by: Chand Shrestha
1 Replies

5. UNIX for Dummies Questions & Answers

File operations are failing inside the script

Hi, does any one know the environmental parameter that I have to set so as to make sure the file operations run properly within the script. right now when I am doing a cat from within the script nothing happens, same is the case when I do a grep. when I am doing awk '{print $0 }' its printing... (1 Reply)
Discussion started by: ahmedwaseem2000
1 Replies

6. Shell Programming and Scripting

Need help in creating file restoration script from a backup script.

Hi all i am struggling in creating a restore of env files while doing applications clone. the first file i created for copying the important configurations file which is running perfect now for reverting the changes i mean when i am restoring these files to its original places i have to do... (7 Replies)
Discussion started by: javeedkaleem
7 Replies

7. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

8. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

9. Shell Programming and Scripting

script to check for a condition inside a file

Hi I am writing a script file which sends the log files along with their size in a folder named log to a file called temp.log using the following cmd: ls -st 190_GSTV_HUX_003QISCGSK026** >> /home/user/temp.log the temp.log looks like this: 16 190_GSTV_HUX_003QISCGSK026_message070321.log ... (11 Replies)
Discussion started by: kiran1112
11 Replies

10. Shell Programming and Scripting

how to find Script file location inside script

I have to find out the file system location of the script file inside script. for example a script "abc.sh" placed anywhere in the file system when executed shold tell by itself the location of it. example #pwd / #./abc this is / #cd /root #./abc this is /root #cd / #/root/abc this... (10 Replies)
Discussion started by: asami
10 Replies
Login or Register to Ask a Question