Solved

running ingres script via cron

Posted on 2009-06-30
31
1,001 Views
Last Modified: 2013-12-26
Hi. SCO OpenServer 5, early Ingres database.  Created the attached script meant to run every X minutes via cron.  The script works fine when run at the user prompt (not root but with db and file system privileges) and produces desire output reliably.  However, the same script produces zero length output file, with no messages delivered to user's mailbox, when cron runs it.  The output log file from the crontab entry mentions "sql: tm: not found" altho the db name is properly cited in the script and works fine manually.  Environment seems to be cited correctly.  I am perplexed, not having seen this behavior before.  Any suggestions?
#ridechrg.sh 12 hour export
 

#062609 - MH

#path
 

PATH=.:/dds/taxi/EXEC:/dds/taxi/TOOL:/dds/ingres/bin:/usr/local/prod:/usr/local/ddsbin:/usr/local/bin:/bin:/usr/bin:/usr/hosts:/etc:/dds/taxi/RNC/EXECUTABLES:/dds/taxi/RNC/TOOLS
 

cd /dds/taxi/TOOL
 

. $HOME/.env
 

dbname=$DATABASENAME
 

sql $dbname << EOF|utl_stripsql|sed -e 's/  //g'>ridechrg.txt
 

select payinfo_seq_a,',',

	trip_id_a,',',

	driver_id_a,',',

	car_id_a,',',

	payment_typ_a,',',

	payment_txt_a,',',

	inum_a,',',

	payment_amt_a,',',

	date_a,',',

	comp_num_a,',',

	hse_num_a,',',

	str_nam_a,',',

	district_a,',',

	unit_num_a,',',

	to_hse_num_a,',',

	to_str_nam_a,',',

	to_district_a,',',

	to_unit_num_a,',',

	mon_tim_a

	from pay_info_r

        where inum_a = '2100' and

        payment_typ_a = 'ACCOUNT' and

        _date(date_a) + (' ' + _time(date_a)) >= (date('now') - date('12 hours')) 

order by trip_id_a;\p\g
 
 

\q

EOF
 
 

		echo "user supervisor password

		cd Utah

		mput ridechrg.txt 

		quit" | ftp -v -i -n localftp
 

#save previous export in case of screw up
 

copy -mov /dds/taxi/TOOL/ridechrg.txt /dds/taxi/MIKE

rm /dds/taxi/TOOL/ridechrg.txt
 

exit 0

Open in new window

ridechrgDOS.log
ridechrgDOSsh.txt
ridechrgcron.txt
0
Comment
Question by:michaelheffernan
  • 18
  • 13
31 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24747294
Hi,

could it be that your $HOME variable is not found?

How do you start the script in cron?

I'd suggest using

0,15,30,45 * * * *  su - dbuser -c "/dds/taxi/TOOL/ridechrg.sh > /dds/taxi/JUNK/ridechrg.log 2>&1"

from root's crontab to have a correct environment.

wmp



0
 

Author Comment

by:michaelheffernan
ID: 24747633
Well, I have substituted the actual db name, "taxi", and not used the variable at all, with the same result.  But you might be on to something with the crontab statement.  I'll try that. Ty
0
 

Author Comment

by:michaelheffernan
ID: 24747735
Well, the script doesn't execute.  See below; I'm using 5 min intervals for testing only.
su as root;
crontab -e and added this line to *root* cron table (the dbuser is "taxi");
stopped and restarted cron as root.
Waited...
No output, nothing in root mail indicating an error.  Have I entered this line correctly?
M

0,5,10,15,20,25,30,35,40,5,50,55 * * * * su - taxi -c "/dds/taxi/TOOL/ridechrg.sh > /dds/taxi/JUNK/ridechrg.log 2>&1"

Open in new window

0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24748131
Seems correct, except for that little typo '...35,40,5,50,...'

Did you watch for execution exactly at quarter to the hour?

Does the line run from a root shell (su - taxi -c "...")?

0
 

Author Comment

by:michaelheffernan
ID: 24748570
I cannot tell. Ineed to remove the redirect from the crontab and then watch. Odd there's no message in mail tho.
0
 

Author Comment

by:michaelheffernan
ID: 24749815
This is the result of the root/cron execution.  Apparently root cannot su the user taxi.  I gather I have to eyeball su for additional parameters....
 
Last   successful real login for taxi: Tue Jun 30 14:15:38 2009 on ttyp2
Last unsuccessful real login for taxi: Tue Jun 30 14:15:33 2009 on ttyp2
stty: tcgetattr failed: No such device (error 19)
sh: 22793 Killed
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24749903
Seems that you are using bash, and one the profiles of 'taxi' contains a command that tries to produce terminal output, such as 'echo'. Remove all statements which try to write to the tty, if possible, and retry!
(profiles - .bashrc, .profile or the like)
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24749973
btw., 'su' hasn't that many parameters. The '-c ...' I suggested doesn't belong to 'su' but is passed to the started shell 'as is'
0
 

Author Comment

by:michaelheffernan
ID: 24749981
Nope, removed the single echo from the .profile (which wasn't being envoked) but still got the same tcgetattrib error and zero length file.  Not bash, tho, sh.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24750007
sh is a link, in almost any case.
Did you verify with a 'normal' login as 'taxi' that there is no terminal output from the shell?
0
 

Author Comment

by:michaelheffernan
ID: 24750055
I see motd, Unix copyright stuff, that's all.  I can su to taxi from the root prompt no problem.  This is getting silly...
1.jpg
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24750101
What about the MAILMSG?
Now I don't know SCO very well, but some systems use 'echo' to display the initial MAILMSG ('you have mail')
Equally, how does SCO display the motd? Might be a problem, too,
I, personally, would change the default shell of 'taxi' to /bin/ksh, which is proven to work in a cron environment, even with echo.
 
0
 

Author Comment

by:michaelheffernan
ID: 24750113
Yeah, but that would blow up a bunch of other stuff.  "taxi" is the main user for the call center, altho the vendor also has everything *else* running as taxi.  Thanks...I will keep banging at it.  Right now, I'd better catch up on the rest of my to do list!
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24750136
OK, in that case you will have to go back to your initial script and try to configure a complete, reliable environment in there.
CU
wmp
 
0
 

Author Comment

by:michaelheffernan
ID: 24750540
..which I think I was doing originally.

PATH=.:/dds/taxi/EXEC:/dds/taxi/TOOL:/dds/ingres/bin:/usr/local/prod:/usr/local/ddsbin:/usr/local/bin:/bin:/usr/bin:/usr/hosts:/etc:/dds/taxi/RNC/EXECUTABLES:/dds/taxi/RNC/TOOLS
cd /dds/taxi/TOOL
. $HOME/.env
dbname=$DATABASENAME
sql $dbname << EOF|utl_stripsql|sed -e 's/  //g'>ridechrg.txt
 
I'm missing something here...time to keep looking.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:michaelheffernan
ID: 24750612
Holy mackeral..."utl_stripsql" is a *ksh* script.  Your hunch might be correct....
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24753255
I can't see any problems with "utl_stripsql" being a ksh script! Why should it do any harm?
I still see only two things in your script -
- $HOME is not set - replace $HOME with the actual path to .env Don't omit the call to .env - I guess it's imperatively needed.
e.g. . /dds/taxi/.env
Mind the '. ' (dot+space) in front - it's mandatory!.
- .env itself - does it contain all required settings, or is there something in the user's .profile which is additionally needed? Also check the ENV variable. Does it contain a path to another initialization script (besides .env)?
 
0
 

Author Comment

by:michaelheffernan
ID: 24755261
You're right; I forgot it is a ksh env.  Okay, lemme look at those aspects.  $HOME is set in the user's .profile, but I will replace the variable with the actual location.  I would have thot that I could use su in the crontab statement to set up the user's complete env and then execute the shell script (su - -c "script" user ), but that didn't work either.  I'll example the .profile and see what all is there.  Here's the env...
Thanks...

taxienv.txt
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24755343
Well, as we both noticed, sh doesn't work with su - taxi -c "..." because of terminal output.
>> $HOME is set in the user's .profile <<  Yes, and that's the big problem. .profile is not executed under cron - you don't get a login shell with cron, and only a login shell executes .profile (and 'su -' does, thus our try).
The .env looks rather good, but I'm not familiar enough with Ingres to be sure.
 
 
0
 

Author Comment

by:michaelheffernan
ID: 24755390
Nope, no change; Even with the env specified, zero output.  "ERget: Not Found Internal Message" is appearing in the output file.  Sheesh...  .env, as you can see, mainly sets up various aspects of terminal input/output and web app stuff.  I see nothing pointing at anything else.  Ditto .profile.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24755477
This looks like a missing path to a message file.
I'd suggest the following -
Perform a normal login as 'taxi', issue 'printenv' or 'set' and compare the output with the settings you made in the script and in .env.
We must be missing some tiny (or not so tiny) detail, that's sure
 
0
 

Author Comment

by:michaelheffernan
ID: 24755507
Yes, you're right.  Lemme hunt...
0
 

Author Comment

by:michaelheffernan
ID: 24755512
Oops, forgot the attachment...
log.txt
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24755548

Is there something like .ingIIsh or .ingIIbsh in .profile (or at least in taxi's HOME)?
If so, this could be the clue, then.
 
0
 

Author Comment

by:michaelheffernan
ID: 24755614
Nope, nothing like that at all.
profile.txt
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24755710
What is cpu_ksh_exit ?
I assume 'mmi' is not needed for the DB query??
Else ... no more idea!
--- Out for a meeting -- Back in 2 hrs. or so ---
0
 

Author Comment

by:michaelheffernan
ID: 24755960
Okay, thanks.  mmi is the primary end user app, not a db item at all.  the cpu_ksh_exit is part of the process that determines if the user is on the primary server or the slave.
Thanks so far....
0
 

Author Comment

by:michaelheffernan
ID: 24758397
You know, I just noticed this message whenever I exit crontab -e:
"Warning: commands will be executed using /bin/sh"
I'm not all that familiar with the differences between sh and ksh, and ksh is the env the user "taxi" operates.  Could this be an issue?
0
 

Author Comment

by:michaelheffernan
ID: 24758414
"Yes!" he exclaimed, having just tried running the script in "sh" instead of "ksh".  "Oh, look," he added, " the *same* bloody error!"  Aye aye aye aye...
So I have to figure out how to run my script in ksh out of cron.  Sheesh again.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 24758610
Normally it should be enough to have
#!/bin/ksh
as first line in the script.

And you can always use in crontab
0,15,30,45 * * * * /bin/ksh /dds/taxi/TOOL/ridechrg.sh > /dds/taxi/JUNK/ridechrg.log 2>&1

I'm not sure if this is the right track.

0
 

Author Closing Comment

by:michaelheffernan
ID: 31598410
Yes, it is the right track.  I added the #! /bin/ksh to the first line and voila!  It works.  I thank you for the help and will give you the credit.  
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Utilizing an array to gracefully append to a list of EmailAddresses
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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now