LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-01-2007, 08:00 AM   #1
boyd98
Member
 
Registered: Oct 2003
Posts: 156

Rep: Reputation: 15
HELP - perl script- doesnt run in cron, but does run in terminal


EDIT - please go to bottom of post for current status

Fellas -

Someone created a script at my work - trying to get this thing to run in cron every night instead of somone manually running it - the issue is when it runs from cron, it cuts off the bottom of the output

my thought was to create a seperate script, and then run it out of cron - but for some reason it still not running correctly, it cuts off the bottom of the output

here is my script, irc_script

#!/bin/bash
stty cols 132
date > /usr/imagedev/sh/daily_chkImages.txt
/usr/imagedev/sh/daily_chkImages.pl >> /usr/imagedev/sh/daily_chkImages.txt
mutt -s "Daily Check Images" -a /usr/imagedev/sh/daily_chkImages.txt "boyd@test.com" < /dev/null

Run the script manually, it creates the output file correctly and then emails it

Run it through cron and it cuts off the bottom of the output and mails a the output with the bottom missing. what would cause this? cron, the .pl file, my bash script? - can't figure this one out?


0 2 * * * /usr/imagedev/sh/irc_script


Any Thoughts,

TIA,

Boyd

Last edited by boyd98; 05-01-2007 at 04:06 PM.
 
Old 05-01-2007, 09:04 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,284

Rep: Reputation: 172Reputation: 172
well I dunno but stty won't do a thing obviously because cron does not run in a terminal.
get rid of that for a kick off.

hint: you can test cron jobs to some extent using at and batch though they run
from the current environment.
 
Old 05-01-2007, 09:22 AM   #3
boyd98
Member
 
Registered: Oct 2003
Posts: 156

Original Poster
Rep: Reputation: 15
Im researching,

Im hoping this is because i didnt put the full path for stty.


changing to

/bin/stty cols 132


although i can't test this until after hours - any other thoughts on why it may be failing?
 
Old 05-01-2007, 09:25 AM   #4
boyd98
Member
 
Registered: Oct 2003
Posts: 156

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by bigearsbilly
well I dunno but stty won't do a thing obviously because cron does not run in a terminal.
get rid of that for a kick off.

hint: you can test cron jobs to some extent using at and batch though they run
from the current environment.

Thks for you feedback - is there anyway to set the width of my output to 132, within cron. Im assuming im only getting half of my output, because cron is not 132?

how would i set its environment variable up
 
Old 05-01-2007, 09:43 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,284

Rep: Reputation: 172Reputation: 172
what are you trying to do?

there is no width in a cron job as there is no terminal.
the width of what?

it's like saying "how do I make my orange louder?"

Last edited by bigearsbilly; 05-01-2007 at 09:44 AM.
 
Old 05-01-2007, 09:56 AM   #6
boyd98
Member
 
Registered: Oct 2003
Posts: 156

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by bigearsbilly
what are you trying to do?

there is no width in a cron job as there is no terminal.
the width of what?

it's like saying "how do I make my orange louder?"

its like this :

if i run this script/command

/usr/imagedev/sh/daily_chkImages.pl >> /usr/imagedev/sh/daily_chkImages.txt - i get an output txt file.

when i run it manually i get a large output, which is formatted with headers and cols based on the .pl script



if i run this through cron, the file gets chopped. output looks something like this

correct output
1
1
1
1
1 2 3 4 5
a b c d e
f g h i j

output if ran through cron

1
1
1
1



my thought was it was failing because stty cols 132 was not set - maybe im looking at it wrong?

thx again for the feedback man - i really need to get this to work - for work
 
Old 05-01-2007, 01:54 PM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

Check to see if a terminal is present, if not: parse login file(s).

The tty command returns your current tty (something like: /dev/ttyp1) or, if no terminal is attached (as is the case with cron) an error (not a tty).

This:
[[ "`/usr/bin/tty`" == "not a tty" ]] && . ~/.profile
will parse the .profile file if no tty is attached.

Hope this helps.
 
Old 05-01-2007, 02:45 PM   #8
boyd98
Member
 
Registered: Oct 2003
Posts: 156

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by druuna
Hi,

Check to see if a terminal is present, if not: parse login file(s).

The tty command returns your current tty (something like: /dev/ttyp1) or, if no terminal is attached (as is the case with cron) an error (not a tty).

This:
[[ "`/usr/bin/tty`" == "not a tty" ]] && . ~/.profile
will parse the .profile file if no tty is attached.

Hope this helps.

I dont know what the deal is - i can run the perl script just fine at the terminal direct it to an out file and its there just great

if i put the thing in cron i get an error:

DBI connect('idb','boyd',...) failed: ERROR OCIEnvNlsCreate (check ORACLE_HOME and NLS settings etc.) at /usr/imagedev/sh/daily_chkImages.pl line 1463

here is line 1463
if ( $READ_LOG_FILE eq '') {
# Connect to DB
$dbh = DBI->connect( 'dbi:Oracle:idb', -line 1463
'boyd',
'i6074',
{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made: $DBI::errstr";


is there some perl logical not set

at the top of my script

i did add

/home/.profile and modified profile to 755?

something else going on here?
 
Old 05-01-2007, 03:03 PM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

How did you go from a bash script in your first post to a perl script in the previous post? Maybe I wasn't clear enough: The line I gave is for your bash script, not perl.

You don't need to change the permissions on .profile (should be 640 or 644).

A bit more info:
When you run from cron, no environment is set (only the bare basics). By parsing your .profile (or .bash_profile) you can set the environment 'manually'. The line I gave checks to see if the script (bash script) is run from cron or a terminal (tty). If it's run from cron, it parses .profile and your environment variables are accessible. You probably need some Oracle related variables that are present in your 'normal' (read: terminal) environment.

Hope this clears things up a bit.
 
Old 05-01-2007, 03:20 PM   #10
boyd98
Member
 
Registered: Oct 2003
Posts: 156

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by druuna
Hi,

How did you go from a bash script in your first post to a perl script in the previous post? Maybe I wasn't clear enough: The line I gave is for your bash script, not perl.

You don't need to change the permissions on .profile (should be 640 or 644).

A bit more info:
When you run from cron, no environment is set (only the bare basics). By parsing your .profile (or .bash_profile) you can set the environment 'manually'. The line I gave checks to see if the script (bash script) is run from cron or a terminal (tty). If it's run from cron, it parses .profile and your environment variables are accessible. You probably need some Oracle related variables that are present in your 'normal' (read: terminal) environment.

Hope this clears things up a bit.

yea sorry it may be confusing - but i very much appreciate the help

i have a perl script that i did not write. it works when ran from the command promt.

what i want to do with it is, automate it and email the output

so i wrote shell script that one, runs the perl script, puts it to an outfile, and then two emails it


i think my issue is the perl script just running in cron will not give the full output.


Have i confused you yet.

also, i tried putting this command in my shell script - "/home/.profile" i changed the permission and verified i could run this

is this not the proper way to pass variables ^
 
Old 05-01-2007, 04:07 PM   #11
boyd98
Member
 
Registered: Oct 2003
Posts: 156

Original Poster
Rep: Reputation: 15
*EDIT - here is the issue very cleaned up

I run a perl script at the OS it works, i run it in CRON either at root or user and it fails with error:

DBI connect('idb','boyd',...) failed: ERROR OCIEnvNlsCreate (check ORACLE_HOME and NLS settings etc.) at /usr/imagedev/sh/daily_chkImages.pl line 1463

i put this perl script inside a shell script trying the following
defining all envs that are currently defined
puting ./.profile at the top of my shell script


I am struggle bad - any feedback is appreciated

THX

Last edited by boyd98; 05-01-2007 at 04:08 PM.
 
Old 05-01-2007, 04:14 PM   #12
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

Like I stated before:

. ~/.profile

You need to parse it, not execute it.

Mind the space between the first dot and the ~!
 
Old 05-01-2007, 06:14 PM   #13
boyd98
Member
 
Registered: Oct 2003
Posts: 156

Original Poster
Rep: Reputation: 15
you are absoutley correct - - thank you for your help -


I was missing this big time.

I was making it an executable because ./home/.profile would not run


the reason for this was because i was missing the . <space> /home/.profile


thx for all your help
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set up cron job to execute bash script lgmqy2000 Linux - General 4 11-22-2006 04:29 AM
Bash script and cron job rust8y Linux - General 2 07-08-2006 07:45 AM
Cron Job with a Script bravored Linux - General 4 08-05-2005 10:27 AM
script not running as a cron job sanjith11 Programming 5 11-23-2004 08:42 AM
putting a math calculation in a cron job the_rhino Linux - Newbie 3 10-11-2004 01:46 PM


All times are GMT -5. The time now is 03:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration