Tag Archives: EOF

Issue with cron and environmental variable

By rafa_fed2

My shell script it.sh.I am calling bip.sh from it.sh

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select 1016 from adj where rownum <2;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 100
done
fi

###Removing temporary log files generated

if [ -f $CUR_DIR/bip_log_1.txt ]
then
`rm $CUR_DIR/bip_log_1.txt`
echo "file bip__log_1.txt removed"
fi

if [ -f $CUR_DIR/sql_output.txt ]
then
`rm $CUR_DIR/sql_output.txt`
echo "sql_output.txt removed"
fi


Code:

59 04 * * * /arbor/integ_fx/rahul_raj/itsr_5652/it.sh /arbor/integ_fx/rahul_raj/itsr_5652


my error.log file

Code:

LOGGING STARTS 07-22-2013 05:22:00

SQLPLUS CONNECTION
SQLPLUS Connection Successful
bip 1016 is running
cat: cannot open /.arborpw
file bip__log_1.txt removed
sql_output.txt removed.
ERROR: $ARBORDBU environment variable is not set

This script requires that the $ARBORDBU environment variable be set.


MY BIP.SH

Code:

#!/bin/sh
ARBOR_DB_PASSWD=`cat $ARBORDIR/.arborpw`; export ARBOR_DB_PASSWD
DB_PASS=$ARBOR_DB_PASSWD; export DB_PASS;
ORACLE_SID=$ARBOR_CATALOG_DATABASE; export ORACLE_SID;
ARBORCTRLRPT03=$ARBORDATA/reports/ctrl; export ARBORCTRLRPT03;

Usage(){
echo "nn Usage is: `basename $0` n"
echo " where is a number between 01 and 99"
echo " is a number. Use 0=production, 3=proforma, 6=backout"
echo " is an arbor accout numbernn"
exit 0
}

# Check number of arguments
if [ "$#" -ne 3 ] ; then
Usage
fi

# Check to see if ARBORDBU is set
if [ -z "${ARBORDBU}" ] ; then
echo "ERROR: $ARBORDBU environment variable is not setn"
echo "This script requires that the $ARBORDBU environment variable be set.nn"<br ...read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Scheduling issues

By rafa_fed2

I AM ON SOLARIS

I have a script it.sh which is running fine when i execute it from shell command.
But when i schedule it in crontab it is throwing error.

Why and how can i resolve it ?i am clueless

IT.SH

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select distinct account_no from adj WHERE ADJ_TRANS_CODE=-2401 and request_status=1 and bill_ref_no=0
order by account_no;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
sh $SCRIPT_DIR/bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 180
done
fi


My error is in error.log

Code:


LOGGING STARTS

SQLPLUS CONNECTION
SQLPLUS Connection Successful
bip 114034 is running
cat: cannot open /.arborpw


my error is bip_log_1.txt

Code:

ERROR: $ARBORDBU environment variable is not set

This script requires that the $ARBORDBU environment variable be set.


My bip.sh is

Code:

#!/bin/sh
ARBOR_DB_PASSWD=`cat $ARBORDIR/.arborpw`; export ARBOR_DB_PASSWD
DB_PASS=$ARBOR_DB_PASSWD; export DB_PASS;
ORACLE_SID=$ARBOR_CATALOG_DATABASE; export ORACLE_SID;
ARBORCTRLRPT03=$ARBORDATA/reports/ctrl; export ARBORCTRLRPT03;

Usage(){
echo "nn Usage is: `basename $0` n"
echo " where is a number between 01 and 99"
echo " is a number. Use 0=production, 3=proforma, 6=backout"
echo " is an arbor accout numbernn"
exit 0
}

# Check number of arguments
if [ "$#" -ne 3 ] ; then
Usage
fi

# Check to see if ARBORDBU is set
if [ -z "${ARBORDBU}" ] ; then
echo "ERROR: $ARBORDBU environment variable is not setn"
echo "This script requires that the $ARBORDBU environment variable be set.nn"
...read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Files not being removed

By rafa_fed2

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select 1016 from adj where rownum <2;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 100
done
fi

###Removing temporary log files generated

if [ -f "$CUR_DIR/bip_log_1.txt" ]
then
rm "$CUR_DIR/bip_log_1.txt"
echo "file bip__log_1.txt removed"
fi

if [ -f "$CUR_DIR/sql_output.txt" ]
then
rm "$CUR_DIR/sql_output.txt"
echo "sql_output.txt removed"
fi


My error

error.log

Code:

SQLPLUS CONNECTION
SQLPLUS Connection Successful
bip 1016 is running
file bip__log_1.txt removed
./it.sh: syntax error at line 76: `end of file' unexpected


how do i remove sql_output.txt

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Another issue with crontab

By rafa_fed2

My shell script it.sh

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select 1016 from adj where rownum <2;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 100
done
fi

###Removing temporary log files generated

if [ -f $CUR_DIR/bip_log_1.txt ]
then
`rm $CUR_DIR/bip_log_1.txt`
echo "file bip__log_1.txt removed"
fi

if [ -f $CUR_DIR/sql_output.txt ]
then
`rm $CUR_DIR/sql_output.txt`
echo "sql_output.txt removed"
fi


when i execute the script manually ,it is working fine but when i schedule this job in crontab i get an error in error.log

Why?
Please help me.

crontab entry

Code:

59 04 * * * /arbor/integ_fx/rahul_raj/itsr_5652/it.sh /arbor/integ_fx/rahul_raj/itsr_5652


Code:


LOGGING STARTS 07-22-2013 05:22:00

SQLPLUS CONNECTION
SQLPLUS Connection Successful
bip 1016 is running
cat: cannot open /.arborpw
file bip__log_1.txt removed
sql_output.txt removed


…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Log file being not generated in crontab

By rafa_fed2

My shell script it.sh

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select 1016 from adj where rownum <2;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 100
done
fi

###Removing temporary log files generated

if [ -f $CUR_DIR/bip_log_1.txt ]
then
`rm $CUR_DIR/bip_log_1.txt`
echo "file bip__log_1.txt removed"
fi

if [ -f $CUR_DIR/sql_output.txt ]
then
`rm $CUR_DIR/sql_output.txt`
echo "sql_output.txt removed"
fi


when i execute the script manually ,it is working fine but when i schedule this job in crontab error.log file is not generated

Why?
Please help me.

crontab entry

Code:

59 04 * * * /arbor/integ_fx/rahul_raj/itsr_5652/it.sh /arbor/integ_fx/rahul_raj/itsr_5652


…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Removing log files

By rafa_fed2

Code:

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

LOG_FILE=error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file
SCRIPT_DIR=`cat .id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat .id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat .id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat .id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<$CUR_DIR/sql_output.txt
set feedback off
set heading off
select 1016 from adj where rownum <2;
EOF

if [ $? -eq 0 ]
then
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are "

if [ ! -s "sql_output.txt" ]
then
echo "No account number for bad debt"
else
for i in `cat sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt
sleep 100
done
fi

###Removing temporary log files generated

if [ -f $CUR_DIR/bip_log_1.txt ]
then
`rm $CUR_DIR/bip_log_1.txt`
echo "file bip__log_1.txt removed"
fi

if [ -f $CUR_DIR/sql_output.txt ]
then
`rm $CUR_DIR/sql_output.txt`
echo "sql_output.txt removed"
fi

rm $CUR_DIR/error.log


I want to remove the 3 files that are being genarated.
How can i do this
I am getting an error

Code:

file bip__log_1.txt removed
./it.sh: syntax error at line 76: `end of file' unexpected


My code should work for all paths that i give

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Connect once db discionnect after all ececution

By krupasindhu18

Hi All,

Please see the below code.

it is working fine when in ‘test_file’ have only one emplid.

test_file contains only emplid and date, like below …
0000221|1/12/2003
0000223|1/1/1996

Problem :-
when test_file contains more then one records(emplids) it is not giving any errors but it is disconnecting from database and
always connecting to database for each and every emplid..

But i want once connect to data base and after perform all execution it would disconnect from data base.
Please help me on this problem.

HTML Code:

#!/bin/sh
set -x
echo "test for multiple values"
UIDPSWD=`cat /projects/feeds/twest/uidpswd`
echo "oracle connection test"
full=/projects/feeds/twest/test_file
#values=`cut -d'|' -f1 $full|sed -e "s/.*/'&'/" -e 's/$/;/g' -e '$s/,$//'`
#below command will work in bourne shell
#values=(`awk -F"|" '{print $1}' $full`)
#below command will work in korn shell
set -A values $(awk -F"|" '{print $1}' $full)
for i in ${values[*]}
do
sqlplus -s $UIDPSWD <>/projects/feeds/twest/result.txt
set serveroutput on
set verify off
set heading off
set feedback off
set ECHO OFF
--spool /projects/feeds/twest/ouput_file.txt
declare
cursor c1
is select emplid,ACTION,ACTION_DT,ACTION_REASON
from ps_job
where emplid='$values';
c2 ps_job%rowtype;
begin
DBMS_OUTPUT.PUT_LINE( 'emplid'|| chr(9) ||'ACTION'|| chr(9) ||'ACTION_DT'|| chr(9) ||'ACTION_REASON');
for i in c1 loop
EXIT WHEN c1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(i.emplid|| chr(9) ||i.action||chr(9)||i.action_dt||chr(9)||i.ACTION_REASON);
end loop;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('test Update query: ' || SQLERRM);
end;
/
exit;
EOF
done


Thanks & Regards,
Krupa

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

In awk: unexpected EOF while looking for matching `"'

By Manasa Pradeep

I am trying to get grep with awk command into variable.
But facing error.
Could someone pls help.

[mhs@flexiaf1 ~]$ cat test_file
DEPLOYMENT=”abc” # com
cluster=”bcn”
[mhs@flexiaf1 ~]$ grep DEPLOYMENT test_file | awk -F “”” ‘{ print $2 }’
abc
[mhs@flexiaf1 ~]$ a=`echo “grep DEPLOYMENT test_file | awk -F “\”” ‘{ print $2 }'”` ; echo $a
-bash: command substitution: line 1: unexpected EOF while looking for matching `”‘
-bash: command substitution: line 2: syntax error: unexpected end of file
[mhs@flexiaf1 ~]$

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

How to get result from both of these modules?

By bluemind2005

Hallo All unix Guru’s

I have written a small (static) pl/sql function which is inserting data into database. It is as follows:

Code:

sqlplus $CONNECT <<-EOF
DECLARE
Counter integer :=1;
BEGIN
WHILE Counter <= ${no_of_files} LOOP
INSERT INTO stuck_files(COL_DATE,SER_NAME,TYPE_FILE,FILENAME,FILE_STATUS) VALUES (sysdate,'pqrs','pqrs','pqrs','pqrs');
Counter := Counter + 1;
END LOOP;
END;
/
commit;
exit;
EOF


However the above “insert” needs to be more of dynamic in nature, as such you can see that we want to insert data depending upon the variable value ${no_of_files}.

Now let me show you another module which is giving me the file(s)names which I want to insert.

Code:

N=0
for i in $(find . -path */waiting/* -type f -not -name "SS*" -mmin +120 -print) ; do

testarray[$N]="$i"
echo "$i"

let "N= $N + 1"
done


Sample Output from above command is as follows:

Code:

/d1/d2/d3/d4/waiting/abcd.txt
/d1/d2/d31/d42/waiting/pqrs.txt
/d1/d2/d32/d43/waiting/xyz.txt


Now the data insert which is given in the above pl/sql block has directly to do with this output. It going to be dynamic in nature.

Let us come back to mapping of how we need to insert data based on this output. I will go through the first insert.2 insert and 3rd insert so you would get an idea of design.
But these are very dynamic, meaning the insert depends on the output produced but yes the directory structure would remain same.

Code:

COL_DATE,SER_NAME,TYPE_FILE,FILEFILENAME,FILE_STATUS
sysdate,d3,d4,abcd.txt,waiting
sysdate,d31,d42,pqrs.txt,waiting
sysdate,d32,d3,xyz.txt,waiting


I believe this can definitely be implemented with help of magic like awk or anything but not able to implement it.

Any ideas/help would be greatly appreciated.

Source: FULL ARTICLE at The UNIX and Linux Forums

Print line by character in C

By yifangt

Hello, I am reading the K & R C book, and trying to understand more about putchar()/getchar() by practice. Similar to the exercise 1-12, I want try to parse each line by character. Although there are many site about the exercise, but I could find similar case of mine, which is similar to fold command. Not sure it’s my code problem, or from my display setting.

Code:

#include
/*count the characters in input; */

main() {
char c;

while (c = (getchar() != EOF) )
{
// putchar(c);
printf("%cn", putchar(c));
}

}


Input:

Code:

A test


And I am expecting output like:

Code:

A

t
e
s
t


But I got strange char on the screen, can’t be pasted here. What did I miss? Thanks!

From: http://www.unix.com/programming/221701-print-line-character-c.html

Escape special character

By sandy162

Hi,
How to use * in call to pl/sql block from shell script?
The line “select * from” is causing all files and directiores to show up in email notification but if I give all column names then it works,
Please let me know how to use ‘*’ instead of giving all column names, in other wirds how to escape special character * ?

Code:

--shell script
${ORACLE_HOME}/bin/sqlplus ${ORACLE_USER}/${ORACLE_PASSWD}@${ORACLE_SID} < ${TMP_LOG_FILE} 2>&1
set serveroutput on
@${CREATE_STAGE_SQL} ${i}
COMMIT;
QUIT;
EOF


Code:

---sql to create staging table
declare
v_sql_string varchar2(4000);
begin
# some code
execute immediate 'create table t1_rpt_&1._stg as select * from t1_rpt_tmt';
end;


thanks
sandy

From: http://www.unix.com/shell-programming-scripting/221377-escape-special-character.html

While loop shubshell problem

By sathyaonnuix

People,

Here is my code

Code:

while read ln
do
xyz=$(echo $ln/$val1*100-100|bc -l|xargs printf "%1.0fn")
if [ "$xyz" -le -50 ] && [ "$xyz" -ne 0 ]; then
iam="YELLOW"
fi
done <<< "$(grep "^[0-9]" $TMPOUT)"


where $TMPOUT is a flat file which contains a set of values.

Whilst executing the above, I get an error

Code:

ABC.ksh: line 136: unexpected EOF while looking for matching `"'
ABC.ksh: line 141: syntax error: unexpected end of file


Where is the problem, how i can correct it. Please help, thanks.

From: http://www.unix.com/shell-programming-scripting/221367-while-loop-shubshell-problem.html

How to get sqlplus column header once in csv file?

By a1_win

Hi All,

Could anyoone please let me know how do I get sqlplus column header once in csv file

Scripts are below:

Code:

cat concreq.sh

#!/bin/bash

. $HOME/.profile

while [ 1 -eq 1 ]; do
sqlplus apps/pwd <<-EOF
set lines 100 pages 100
col "USER_CONCURRENT_QUEUE_NAME" format a40;
--set termout off
--set arraysize 5
set echo off
set verify off
set heading on
set feed off
set colsep,;
@/test1/concreq.sql
EOF
sleep 15
done
$


Code:

$cat concreq1.sql

column tm new_value file_time noprint
select to_char(sysdate, 'MMDDYYYY') tm from dual ;
prompt &file_time
spool /test1/TEST1_CM_&file_time..csv append
col running head "Running" format 9999999
select to_char(r.ACTUAL_START_DATE,'MM-DD-YYYY HH24:MI:SS'),sum(decode(r.phase_code,'R',1,0)) - sum(decode(r.status_code,'W',1,0)) running,sum(decode(r.phase_code,'P',1,0)) pending
from applsys.fnd_concurrent_requests r,applsys.fnd_concurrent_processes p,applsys.fnd_concurrent_queues q
Where r.controlling_manager (+) = p.concurrent_process_id
and p.queue_application_id = q.application_id
and p.concurrent_queue_id = q.concurrent_queue_id
and q.max_processes >= 0 and (r.phase_code in ('R','P','I'))
group by r.ACTUAL_START_DATE
UNION ALL
SELECT (to_char(sysdate,'MM/DD/YYYY HH24:MI:SS')),0,0 from dual
WHERE NOT EXISTS
(select to_char(r.ACTUAL_START_DATE,'MM-DD-YYYY HH24:MI:SS'),sum(decode(r.phase_code,'R',1,0)) - sum(decode(r.status_code,'W',1,0)) running,sum(decode(r.phase_code,'P',1,0)) pending
from applsys.fnd_concurrent_requests r,applsys.fnd_concurrent_processes p,applsys.fnd_concurrent_queues q
Where r.controlling_manager (+) = p.concurrent_process_id
and p.queue_application_id = q.application_id
and p.concurrent_queue_id = q.concurrent_queue_id
and q.max_processes >= 0 and (r.phase_code in ('R','P','I'))
group by r.ACTUAL_START_DATE);
spool off;
-bash-3.2$


Code:

Current output after executing the concreq.sh script:

-bash-3.2$ cat TEST1_CM_04102013.csv

TO_CHAR(R.ACTUAL_ST, Running, PENDING
-------------------,--------,----------
04-16-2013 19:03:32, 1, 0

TO_CHAR(R.ACTUAL_ST, Running, PENDING
-------------------,--------,----------
04-16-2013 19:03:32, 1, 0

TO_CHAR(R.ACTUAL_ST, Running, PENDING
-------------------,--------,----------
04-16-2013 19:03:32, 1, 0

$


Expected output should be:

Code:

-bash-3.2$ cat TEST1_CM_04102013.csv

TO_CHAR(R.ACTUAL_ST, Running, PENDING
-------------------,--------,----------
04-16-2013 19:03:32, 1, 0
04-16-2013 19:03:32, 1, 0
04-16-2013 19:03:32, 1, 0
$


Thanks for your time!

Regards,
a1_win

From: http://www.unix.com/shell-programming-scripting/221303-how-get-sqlplus-column-header-once-csv-file.html

How to use special character in procedure call?

By sandy162

Hi,
I have following script which calls sql to create staging table like t1_rpt_1day_stg,t1_rpt_7day_stg

The following line has ‘*’ and causing all data in directory to show up in email notification but if I give all column names then it works,
Please let me know how to use ‘*’ instead of giving all column names.

Code:

'create table t1_rpt__stg as select * from t1_rpt_tmt'


–shell script

Code:

load_data_to_oracle()
{
# truncate or create stage table first
${ORACLE_HOME}/bin/sqlplus ${ORACLE_USER}/${ORACLE_PASSWD}@${ORACLE_SID} < ${TMP_LOG_FILE} 2>&1
set serveroutput on
@${CREATE_STAGE_SQL}
COMMIT;
QUIT;
EOF

## Function Main

# variables
CREATE_STAGE_SQL=${SQL_DIR}/stage_create.sql

load_data_to_oracle
exit 0


—sql to create staging table

Code:

stage_create.sql
declare
v_sql_string varchar2(4000);
begin
# some code
execute immediate 'create table t1_rpt__stg as select * from t1_rpt_tmt';
#some error checking
end;


Thanks
Sandy

From: http://www.unix.com/shell-programming-scripting/221205-how-use-special-character-procedure-call.html

Trying to create a script to run as root, permission denied

By DonnieNarco

Hello all, I am trying to create a script or a .command file that will run for me and my other techs on many, many Mac OSX computers that will add a file to the /etc/ folder called /etc/launchd.conf

Every time I try to run the script, I get “Permission Denied” when trying to put the file into the /etc/ directory.

The reason for this script is we will need to deploy this script quickly across many Macs, and it will only be run by myself or other admins. We just want to make it easier for us so we do not have to manually go to the /etc/ folder and create the launchd.conf file each time. I dont mind having to type in the root password at launch of this script, but I would prefer to not have to type in the root password each time…i would love it if this could be completely autonomous.

here are the two versions of code that I have tried so far, based on help from other Google inquiries:

Code:

#!/bin/bash

clear ; echo This script will put a system configuration file into your Mac OSX that will assist with UNIX permissions on the IFS

clear ;
echo Moving Working Directory to the System Directory
cd /etc/

echo Creating a new file with correct permissions, please have system root password ready...

sudo cat <> launchd.conf
umask 000
EOF
echo Process has completed, thank you.


and this:

Code:

#!/bin/bash

clear ; echo This script will put a system configuration file into your Mac OSX that will assist with UNIX permissions on the IFS
sleep 2
clear ;

chown root Test3.command
chmod u+s Test3.command

echo Moving Working Directory to the System Directory
cd /etc/
sleep 2
echo Creating a new file with correct permissions, please have system root password ready...
sleep 3
sudo cat < launchd.conf
umask 000
EOF
echo Process has completed, thank you.
sleep 2


Does anyone know how I can create this script for us to run?
Thank you very much.

From: http://www.unix.com/shell-programming-scripting/220907-trying-create-script-run-root-permission-denied.html

How to pass bash variable inside EOF?

By Akshay Hegde

Hi all I am trying to generate some program using following command

Code:

n=1
for file in `ls *.txt | sort -t"-" -k2n,2`;do

nc=`awk 'END{print NR}' $file`

cat >program_$n.xyz<<EOF

let linecount = $nc

some more commands

EOF

n=`expr $n+1`
done


here my problem is

Code:

$nc


inside

Code:

EOF


is not working, those who have solution kindly help me.

Source: FULL ARTICLE at The UNIX and Linux Forums

Call procedure multiple time

By sandy162

Hi,

I have following script which calls sql to create staging table.How do I call load_data_to_oracle() multiple times so that it creates 4 staging as follows.

Code:

1.t1_rpt_1day_stg
2.t1_rpt_7day_stg
3.t1_rpt_30day_stg
4.t1_rpt_CTD_stg


–shell script

Code:

load_data_to_oracle()
{
# truncate or create stage table first
${ORACLE_HOME}/bin/sqlplus ${ORACLE_USER}/${ORACLE_PASSWD}@${ORACLE_SID} < ${TMP_LOG_FILE} 2>&1
set serveroutput on
@${CREATE_STAGE_SQL}
COMMIT;
QUIT;
EOF

## Function Main

# variables
CREATE_STAGE_SQL=${SQL_DIR}/stage_create.sql

##function call
if [[ $type = 'a' || $type = 'A' ]]
then
load_data_to_oracle
exit 0
fi


—sql to create staging table

Code:

stage_create.sql
set serveroutput on size 1000000
declare
v_err_code varchar2(500);
v_err_mesg varchar2(1000);
v_table_name varchar2(100);
v_sql_string varchar2(4000);
v_table_exists number;
begin
# some code
execute immediate 'create table t1_rpt__stg as select * from t1_rpt_tmt';
#some error checking
end;


Thanks
Sandy

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Execution problem with the FTP shellscript

By Kannannair

Hi Friends

I am new to the shell script and i have a script which will connect to server enviornment which will read a file and will FTP to an another server location. But while executing this script FTP transfer is not occuring. But when I enter in FTP mode I am able to transfer the file from one server to another.

Script is

Code:


#!/bin/sh
FILE_NAME="/user/sba-appl/productie/sscr/ramu/dd.DAT"
HOST='130.144.240.108'
USER='user name'
PASSWD='password'
ftp -nv <<EOF
open $HOST
user $USER $PASSWD
cd /user/sba-appl/test/sscr/ramu
put $FILE_NAME
EOF


The error which I am getting is 553. The problem is I cant change the chmod permission of the target server as it is an production server. the root directory user doesnt have a write permission. But while using FTP mode I am able to write the the file but through script I am getting 553 error.Can anybody tell me how to solve this problem.Whether I can use symbolic links??. But If i am able to transfer the file using th FTP mode why it is not working with the script??

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Shell : sftp autologin not working …

By scriptscript

Hi folks,

for sftp autologin, while browing in unix.com forums.. I got the below code. I tried to execute that code but no luck.

Code:

#!/bin/sh
HOST=yourservername
USER=yourusername
PASS=yourpassword
echo "sftping file ..."
lftp -u ${USER},${PASS} sftp://${HOST} <<EOF
cd /tmp
get tmpfile
bye
EOF
echo "done"


the error message is as follows

Code:

ubuntu1[johng]/mypath>sh sftp_new.sh
sftping file ...
sftp_new.sh: line 8: lftp: command not found


Could anyone please help me what went wrong….

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Detail on For loop for multiple file input and bash variable usage

By Akshay Hegde

Dear mentors, I just need little explanation regarding for loop to give input to awk script

Code:

for file in `ls *.txt |sort -t"_" -k2n,2`; do

awk script $file

done


which sorts file in order, and will input one after another file in order to awk script

suppose if I have to input 2 or more than two file in order to awk what I need to do

case is something like this

Code:

for loop

awk script file_1 file_2 file_3

done


in next increment it should

Code:

input file_4 file_5 and file_6


and I do program normally by FORTRAN or C, don’t know much about shell

every time I have to edit in and out file in Fortran code and then I have to compile and run .for code

is there any solution like EOF for fortran to use bash variable in fortran code for in and out file replacement and execute the same.

Kindly anyone explain on this topic.

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums