Cron troubles


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cron troubles
# 1  
Old 03-22-2010
Bug Cron troubles

I am aware this question has been answered time and again. I feel I have tried everything I have seen on the net and really need help to get this working.

Same old story. Shell script, working from command but not from cron. I need my script to take values from a .properties file. Tried everything I have seen to set up enviroment to get this to happen but nothing has worked.

I relelize my ENV_CONFIG(the properties file) isn't in the path for the cron. How do I get it there? (Please be as obvious as possible...I am new to Cron)

crontab
Code:
00 16 * * 1 /apps/myapp/myapp-messaging/purge_msg.sh 2>&1 >

my script
Code:
#!/bin/ksh

NOW=$(date +"%Y-%m-%d-%H%M")

LOGFILE="/apps/myapp/myapp-messaging/logs/purge_log-$NOW.log"

userconfig=`sed -n '/^app.user/p' $ENV_CONFIG`
user=`echo $userconfig| cut -d = -f 2-`

passwd=`sed -n '/^app.password/p' $ENV_CONFIG`
password=`echo $passwd| cut -d = -f 2-`

db=`sed -n '/^app.url/p' $ENV_CONFIG`
dbname=`echo $db| cut -d : -f 6-`
echo "starting purge"

sqlplus -s /NOLOG >$LOGFILE << EOF
conn $user/$password@$dbname
SET SERVEROUTPUT ON size 50000
execute myStoredProcedure
quit
EOF

echo "purge complete"



---------- Post updated at 11:40 AM ---------- Previous update was at 11:30 AM ----------

P.S. Been here and tried everything....maybe I misunderstood it but don't think I don't know it exists!

https://www.unix.com/answers-frequent...n-crontab.html
# 2  
Old 03-22-2010
You have to make the script "experience" login just as you would personally login.
This assume you have a .profile in your home directory.
Code:
#!/bin/ksh

.  /etc/profile
.  /home/airalpha/.profile
. [and /full/path/filename for any  other script you may optionally run manually for set up ]

NOW=$(date +"%Y-%m-%d-%H%M")

LOGFILE="/apps/myapp/myapp-messaging/logs/purge_log-$NOW.log"

userconfig=`sed -n '/^app.user/p' $ENV_CONFIG`
user=`echo $userconfig| cut -d = -f 2-`

passwd=`sed -n '/^app.password/p' $ENV_CONFIG`
password=`echo $passwd| cut -d = -f 2-`

db=`sed -n '/^app.url/p' $ENV_CONFIG`
dbname=`echo $db| cut -d : -f 6-`
echo "starting purge"

sqlplus -s /NOLOG >$LOGFILE << EOF
conn $user/$password@$dbname
SET SERVEROUTPUT ON size 50000
execute myStoredProcedure
quit
EOF

echo "purge complete"

# 3  
Old 03-22-2010
Thanks for your reply Jim.

The .profile suggestion was not one I could use I am afraid. The code was going to deployed on different enviroments and the .profile could not be relied on in each one.

I have found a soloution though!

I needed to set up my variables in the script (obviously). But what I did not realize and haven't seen documented is that the sqlplus path must be set if you are using that too. The top of my code looked like :

Code:
#!/bin/ksh

export ORACLE_HOME=/orcl/app/oracle/product/10.2.0/client_1
export PATH=$PATH:$ORACLE_HOME/bin
export ENV_CONFIG=/apps/myapp/conf/myapp.properties

NOW=$(date +"%Y-%m-%d-%H%M").....

Hope this helps someone else!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Troubles running DB2 command in shell script via cron

Hi there, Now I'm facing error regarding running shell script via cron. The shell script which is required to get value from database. Below is the main part of shell script. #/bin/bash #connect to database(1) db2 connect to $database user xxxx using yyyy #set values from... (3 Replies)
Discussion started by: Rohan Kishibe
3 Replies

2. UNIX for Advanced & Expert Users

Troubles with OpenSSH

Hi, I am trying to login from one AIX server to another without using a password, a basic configuration, however it doesn't seem to work. All things are in place. I have both a public and private key in the ~/.ssh folder and also have an "authorized_keys" file on the target-server containing... (5 Replies)
Discussion started by: Hille
5 Replies

3. BSD

PF troubles on OpenBSD 5.0

I am setting up a system as an ADSL gateway. ADSL is working fine. PF is not forwarding for some reason. # ifconfig lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33196 priority: 0 groups: lo inet6... (0 Replies)
Discussion started by: John Tate
0 Replies

4. Shell Programming and Scripting

Encoding troubles

Hello All I have a set of files, each one containing some lines that follows that regex: regex='disabled\,.*\,\".*\"'and here is what file says about each files: file <random file> <random file> ASCII text, with CRLF line terminatorsSo, as an example, here is what a file ("Daffy Duck - The... (3 Replies)
Discussion started by: tukuyomi
3 Replies

5. Shell Programming and Scripting

if-statement troubles

I try to compare the day and month of someones birthday with the day and month of today, so my little bash script can send a mail to the person that has its birthday that day. The first line of the file birthdays looks like this: firstname,lastname,01/01/1990,.... The variable birthday's... (4 Replies)
Discussion started by: doc.arne
4 Replies

6. HP-UX

cron troubles

I have a cronjob that I need to run everyday and it needs to have todays date inputed, here is what I have, but is not working as expected.......... 23 02 * * * cd /path;./RequestSummaryReport.sh $(date +%Y-%m-%d) the output from mail gives me............. Date: Fri, 8 Feb 2008 02:12:07... (4 Replies)
Discussion started by: theninja
4 Replies

7. UNIX for Dummies Questions & Answers

ssh2 troubles

I'm trying to set up a secure and trusted connection between 2 boxes running solaris using ssh2. I've run ssh-keygen2 on the local box and on the remote box, created the identification file ( IdKey id_dsa_2048_a ) on the local machine and copied across the public key file from the local to... (5 Replies)
Discussion started by: PaulC
5 Replies

8. UNIX for Dummies Questions & Answers

Password Troubles

I'm very new to UNIX (I just started working with Terminal 2 days ago) and I don't know the system very well. I'm having trouble whenever I am asked for a password. I simply... can't type. I press keys on the keyboard but no characters appear on the screen. For example, when I log onto... (5 Replies)
Discussion started by: alexmiller
5 Replies

9. Programming

Troubles with HPUX

Hello I created an application in c language for HP-UX operative system,and it runs on a 32 bits PARISC processor. My problem is that I have to run this same application but now in a 64 bits Parisc processor. But I am not able to compile the application with the 64 bit server, and I only could use... (1 Reply)
Discussion started by: masterboy6666
1 Replies

10. UNIX Desktop Questions & Answers

NetBSD Troubles

HI, I just installed NetBSD i386 v. latest. I am having a few problems: For some reason X just won't start!? Another is I can't access My CDROM or Floppy. Thanks in advance! (3 Replies)
Discussion started by: vertigo
3 Replies
Login or Register to Ask a Question