Script not working via crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script not working via crontab
# 1  
Old 02-08-2015
Script not working via crontab

Hi,
I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly help.

script contents:

Code:
#!/bin/bash
sqlplus -s /nolog << EOF
CONNECT plmc/plmb@whb
@csvgenerator.sql
end;
/
EOF

-----------------------------------
Script running successfully as below, running fine

Code:
$ sh test.sh
Session altered.
CSV generated

In addition to the above info the oracle home profile is already set and each using absolute path for each file as below.

Crontab entry:
Code:
06 00 * * * ksh  ". ./.profile; /data2/users/cmw/PKG12/test_data.sh" > /tmp/testoutput.txt 2>&1

Script:
Code:
#!/bin/ksh
/export/home/oracle/app/oracle/product/11.2.0/client_1/bin/sqlplus -s /nolog << EOF
CONNECT user/user_1234@CBDTEST
@extract_data.sql [checked absolute path for too]
end;
/
EOF

# 2  
Old 02-08-2015
Good to see that you know about cron's environment restrictions and take adequate measures.

But, regarding your problem: Not sure I understand.

You are happily running one script from the command line, but are worried that executing a totally different script using a different shell connecting to a different user on a different host is giving you errors.
That is not an immediate contradiction.

What are the errors that you encounter? Are you sure the right .profile is being sourced?
# 3  
Old 02-08-2015
Also note that using ksh like this, is problematic, since there is no path specified to this shell, so it may be that ksh will not be found.
Also the syntax is incorrect. To make ksh run a command specified on the command line, it requires the -c option.

Since the script contains a shebang, just make sure it is executable and run it with the absolute path to the script (or make sure the PATH is set and that it contains the directory where the script is located):
Code:
/data2/users/cmw/PKG12/test_data.sh > /tmp/testoutput.txt 2>&1

Where the profile is sourced within the script, also with an absolute path to the profile..
# 4  
Old 02-08-2015
can anyone assist here?
# 5  
Old 02-08-2015
Not unless you provide answers.
# 6  
Old 02-08-2015
Quote:
Originally Posted by ash12345
can anyone assist here?
Also please be so kind as to inform us what - in your view - is wrong with the two reactions you have already received and why -in your view - these do not qualify as "assistance".
# 7  
Old 02-08-2015
Seems there is no issue in executing script

Below is the error i am getting when iam running by crontab.

SP2-0310: unable to open file "extract_data.sql "
SP2-0042: unknown command "end" - rest of line ignored.
SP2-0103: Nothing in SQL buffer to run.

Scrutinizer, seems there is no problem in shell [ksh/sh] as the later part of the script is giving output as expected and i think script is failing to connect to DB server and not generating CSV..
Code:
#!/bin/ksh
/export/home/oracle/app/oracle/product/11.2.0/client_1/bin/sqlplus -s /nolog << EOF
CONNECT user/user_1234@CBDTEST
@extract_data.sql [checked absolute path for too]
end;
/
EOF

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Linux ksh script not working in crontab

I am Not sure why following script is not capturing the counts only when using crontab !! when I run it fromt he command line it is fine ! what is missing here ! #!/usr/bin/ksh host=`uname -n` tdate=`date` userid='dbid/password' totalevents=`sqlplus -s $userid << - set timing off ... (1 Reply)
Discussion started by: mrn6430
1 Replies

2. Shell Programming and Scripting

Script not working via crontab

Hi, I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly... (1 Reply)
Discussion started by: ash1234
1 Replies

3. Red Hat

Script not working if crontab scheduled

Hi all, I'm working to a script with /bin/bash shebang. The script works perfectly if I run from command line. The script runs under a non root user and inside the commands are set with sudo command in a such a way they can be run under root, for example (first rows of the script):... (5 Replies)
Discussion started by: idro
5 Replies

4. Shell Programming and Scripting

Expect script not working in crontab with minicom

Hi All, I am testing expect script in command prompt without issue, but in crontab it is not working, i check the output error as below: #cat /var/log/testexp.log spawn minicom -C /var/log/minicom1.log No cursor motion capability (cm) AT+COPS=? I am new in scripting, together... (1 Reply)
Discussion started by: elingtey
1 Replies

5. UNIX for Dummies Questions & Answers

Script is not longer working in the crontab

This is the crontab it is supossed to be running everyday but it didnt 5 0 * * * /export/app/CO/opge/scr/Informe_parametros_colombia.ksh >/dev/null 2>&1 Inside the above script connects to a database and extract data to a flat file, manually i run the script at about 2 a.m. and Works OK,... (6 Replies)
Discussion started by: alexcol
6 Replies

6. Shell Programming and Scripting

Script not working in crontab

Hi I have created a script. Which i have configured in cron to make it run in every 2 min. But script is not running. If I checl the cron log at /var/cron/log .it shows its running in every 2 min. Below is the command which i configured in crontab. But I am not able to find the way so that... (9 Replies)
Discussion started by: nandan8a
9 Replies

7. Shell Programming and Scripting

My script stops working when using crontab

I have made a shell script(/bin/sh) that starts a perl script (that I haven't made my self) that's starts a ssh session. The ssh session uses a private/public key to login so no password is needed. The Perl script works perfect. But when I put it in a cronjob (crontab) the ssh connection asks... (6 Replies)
Discussion started by: splinter_cell
6 Replies

8. Shell Programming and Scripting

Expect Script Not working with Crontab

I have the following expect script sitting on a Linux box. === #!/usr/bin/expect -f # # backup.expect # # Expect script to backup a firewall via a SSH session # # set firewall set username set password set prompt set filename match_max 50000 spawn ssh -l... (2 Replies)
Discussion started by: alagondar
2 Replies

9. Shell Programming and Scripting

script not working from crontab, executes individual

Hi, This script is working successfully when i executed from shell prompt, but the same script scheduled in crontab its not deleting the files, #! /bin/bash DAY_1=`(date --date='4 months ago' '+%Y-%m')` log=/tmp/cleant adir=/u01/app/oracle/admin/talon/adump... (4 Replies)
Discussion started by: saha
4 Replies

10. Shell Programming and Scripting

Script is not working when put in crontab

Hi there, this is part of my script: /usr/bin/cd /u01/oradata /usr/bin/cp `/bin/ls -1 . |grep -v "^DIMStemp01.dbf$" | grep -v "^DIMSts01.dbf$"|grep -v "^DIMStects01.dbf$"` /backup It's working fine when I manually run on telnet session. /bin/ls -1 . -- to list all the files inside... (2 Replies)
Discussion started by: *Jess*
2 Replies
Login or Register to Ask a Question