Link to home
Start Free TrialLog in
Avatar of michaelheffernan
michaelheffernan

asked on

running ingres script via cron

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
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

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



Avatar of michaelheffernan
michaelheffernan

ASKER

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
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

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 "...")?

I cannot tell. Ineed to remove the redirect from the crontab and then watch. Odd there's no message in mail tho.
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
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)
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'
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.
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?
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
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.
 
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!
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
 
..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.
Holy mackeral..."utl_stripsql" is a *ksh* script.  Your hunch might be correct....
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)?
 
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
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.
 
 
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.
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
 
Yes, you're right.  Lemme hunt...
Oops, forgot the attachment...
log.txt

Is there something like .ingIIsh or .ingIIbsh in .profile (or at least in taxi's HOME)?
If so, this could be the clue, then.
 
Nope, nothing like that at all.
profile.txt
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 ---
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....
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?
"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.
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.