0

I have written the following script but i am getting error sqlcorn.sh: No such file or directory

here is the script

#!/bin/bash
ORACLE_HOME="/opt/app/oracle/product/11.2.0/dbhome_1"
ORACLE_SID="HEER"
ORACLE_USER="USER1"
ORACLE_PASSWORD="USERP"

echo "export ORACLE_HOME=$ORACLE_HOME" >> sqlcronprocedure.sh
echo "export PATH=\$ORACLE_HOME/bin:\$PATH" >> sqlcronprocedure.sh
echo "export ORACLE_SID=$ORACLE_SID" >> sqlcronprocedure.sh
echo "rTmpDir=/tmp" >> sqlcronprocedure.sh

echo "sqlplus -s $ORACLE_USER@$ORACLE_SID/$ORACLE_PASSWORD  > $rTmpDir/deleteme.txt 2>&1 <<EOF" >> sqlcronprocedure.sh
echo "    select 1 from dual;" >> sqlcronprocedure.sh
echo "    execute someproc(1000,14);" >> sqlcronprocedure.sh
echo "EOF" >> sqlcronprocedure.sh

chmod 755 sqlcronprocedure.sh

crontab -l > sqlcron.sh
echo "0,15,30,45 * * * * /sqlcronprocedure.sh" >> sqlcron.sh
crontab sqlcorn.sh

This is my first ever script. so i apologize if things are too obvious to ask

1
  • 1
    Nice job for your first script -- except for the typo (see my answer). Commented Jan 31, 2012 at 19:44

2 Answers 2

2

The real problem: You misspelled the file name on the crontab command. Change it from:

crontab sqlcorn.sh

to

crontab sqlcron.sh

Some more comments on your code:

Your multiple echo commands are better written as a "here document". Rather than this:

echo "export ORACLE_HOME=$ORACLE_HOME" >> sqlcronprocedure.sh
echo "export PATH=\$ORACLE_HOME/bin:\$PATH" >> sqlcronprocedure.sh
echo "export ORACLE_SID=$ORACLE_SID" >> sqlcronprocedure.sh
echo "rTmpDir=/tmp" >> sqlcronprocedure.sh

echo "sqlplus -s $ORACLE_USER@$ORACLE_SID/$ORACLE_PASSWORD  > $rTmpDir/deleteme.txt 2>&1 <<EOF" >> sqlcronprocedure.sh
echo "    select 1 from dual;" >> sqlcronprocedure.sh
echo "    execute someproc(1000,14);" >> sqlcronprocedure.sh
echo "EOF" >> sqlcronprocedure.sh

you can do this:

cat <<EOF >sqlcronprocedure.sh
export ORACLE_HOME=$ORACLE_HOME
export PATH=\$ORACLE_HOME/bin:\$PATH
export ORACLE_SID=$ORACLE_SID
rTmpDir=/tmp
EOF

cat <<END_OF_SCRIPT >sqlcronprocedure.sh
export ORACLE_HOME=$ORACLE_HOME
export PATH=\$ORACLE_HOME/bin:\$PATH
export ORACLE_SID=$ORACLE_SID
rTmpDir=/tmp

sqlplus -s $ORACLE_USER@$ORACLE_SID/$ORACLE_PASSWORD  > $rTmpDir/deleteme.txt 2>&1 <<EOF
    select 1 from dual;
    execute someproc(1000,14);
EOF
END_OF_SCRIPT

which is a bit easier to read. (Your version wasn't incorrect, just hard to read and error-prone; you have to get the >> sqlcronprocedure.sh right on eacn and every line.)

Note: You use >> to build sqlcronprocedure.sh, which appends to the existing sqlcronprocedure.sh if it exists. I don't think that's what you want to do; you probably want to create the file from scratch. My code assumes you want to create the file rather than appending to it.

The last part of your script:

crontab -l > sqlcron.sh
echo "0,15,30,45 * * * * /sqlcronprocedure.sh" >> sqlcron.sh
crontab sqlcorn.sh

is fine except for two things.

First sqlcron.sh is not a good name for the file, since it's not a shell script; just call it sqlcron. The system doesn't care, but you should.

Second, the misspelling I mentioned above.

Sign up to request clarification or add additional context in comments.

Comments

-1

you need to specify the full path to sqlcron.sh in your script...

3 Comments

I have modified my script and has added this command when writing to file ${PWD##*/}filename but i am still getting error sqlcron.sh: No Such file or Directory
No, you don't. sqlcron.sh isn't a shell script; it's just given as an argument to crontab. And ${PWD##*/} doesn't refer to the current directory anyway; ${PWD} does. @EmAe: Why did you accept this answer?
he made me realize what the msitake was .. I was referring to a sqlcorn at one place .. i should have referred to sqlcron :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.