crontab not executing

Posted on 2014-04-06
Last Modified: 2014-04-06
this is my shell


dummy=`sqlplus -s  'sakthi_r/gcp_ro_access@(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = = 1780))
        (CONNECT_DATA =
              (SERVER = DEDICATED)
                    (SERVICE_NAME = DPWGCP)
                          )'  <<EOF
                          SET HEA OFF PAGES 0
                              select count(*) from gcb_dba.gcb_charge_dtls ;

                          print "${dummy}"

                              if [ "$dummy" -gt 1 ]; then
                                # mailx -s "Something bad happened in production"
                                echo "something" | mailx -s "subject"
                                    print "1"

                                     sqlplus 'system/system@dcsss'  << EOF

                                         insert into abcd values (1);

and this is my cron tab entry

21,22,23,24,25,26,27,28,29,30,31,45,46,47,48,49,50,51,52,53,54,55 * * * * /home/opctusr1/test/new.ksh >> /home/opctusr1/test/test.log

time of the test.log is changing. but my crontab job is not executing.

when I try to execute normally, it is fine. but only from cron job it is not executing.

Please help me resolve this.
Question by:sakthikumar
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
LVL 40

Accepted Solution

omarfarid earned 500 total points
ID: 39981146
Please note for crontab scripts, you need to:

1- set all required env variables
2- use full path names to files and dires
3- redirect stdin, stdout, and stderr
4- Make sure that the script is executable

Make sure to run the script with the right user (e.g. oracle)

Author Comment

ID: 39981161
Which environment variables i need to set.?
 I have given 777 privs to user.
how can I get / identify the full path.
LVL 40

Assisted Solution

omarfarid earned 500 total points
ID: 39981168
Please look in the user's home directory for .profile file and see what env variables ae set. You may set PATH and Oracle env. as example.

One quick way is to run commands like




and see relevant env variables required.

Also, if you don't set PATH then you need to use full path name to commands like sqlplus, mailx, etc.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 40

Assisted Solution

omarfarid earned 500 total points
ID: 39981169
For you to get the full path name for commands, you may run command

which sqlplus

which mailx

Author Comment

ID: 39982232

I have added the below lines in my shell script.

export PATH

But still I am getting the error.
when I tried which sqlplus

In the log, I am getting error.
sqlplus not found

Author Comment

ID: 39982241
I am a beginner in unix, please tell me exactly where should I execute what commands to get it right..

Author Comment

ID: 39982253
Thank you very much Omar, I got it atlast.
LVL 40

Expert Comment

ID: 39982261
Welcome :)

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question