Running script that sends an html formatted email fails when its run as cronjob


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running script that sends an html formatted email fails when its run as cronjob
# 1  
Old 09-16-2008
Running script that sends an html formatted email fails when its run as cronjob

Hi

Im very new at working with unix and this problem I simply can not understand. I know there are a lot of threads about problems with shell scripts behaving differently when run from a terminal and from a cronjob. I have tried everything(almost) but I still havent cracked this problem.

Im working with typo3 and an extension called aux_newsmailer. The extension, when working properly, is suppose to send out newsletter automatically to users. Either formatted as plain text or html. My problem is that the extension has a backend userface where you manually can send the newsletters which works. Also, running the mailer script from a terminal works fine. When I, however, tries to run the script from a cronjob the html mails are somehow not received by all users and those mails that does are not formatted correctly, images are missing and links are not formatted the right way.

I have concluded that the error has something to do with the sending/formatting process but thats all I know.

Has anyone any idea what might be the problem?

/Nightowl
# 2  
Old 09-16-2008
The usual problem when a cron job script doesn't work, but the script works from the command line is that the environment is different. Usually, the PATH must be defined in the script.

If the problem is not the PATH, check other variables that the script depends on.
# 3  
Old 09-16-2008
Ok, I have been around this before and the environment is quite different, though, Im not sure which variables the script depends on or how to change the variables like PATH. How is this done?

I have tried to type:
PATH=/root/bin etc, but this returns an error

Can you help?
# 4  
Old 09-16-2008
What is the error that u r getting?

PS:U can place 2>error.log in ur cron script to get the error messages logged to a file.
# 5  
Old 09-16-2008
Quote:
Originally Posted by Nightowl
Ok, I have been around this before and the environment is quite different, though, Im not sure which variables the script depends on or how to change the variables like PATH. How is this done?

Read the script and see what variables it uses but does not set.
Quote:
I have tried to type:
PATH=/root/bin etc,

Where did you type it?

What, exactly, did you type?
Quote:
but this returns an error

What is the error?
# 6  
Old 09-16-2008
I dont think any of the variables are actually used or I just dont get it Smilie

Here is the shell script written in php:

#! /usr/bin/php -q
<?php


// set typo path to point to the root of the T3 installation
$typopath='/var/www/typo3/mysite/';

// create a BE user called _cli_auxnewsmailer (must not be admin), for better security change it to somethine else.
$MCONF['name'] = '_CLI_auxnewsmailer';

// *****************************************

// Standard initialization of a CLI module:

// *****************************************


if (@is_file($typopath.'typo3conf/ext/aux_newsmailer/mod1/index.php'))
$modulepath=$typopath.'typo3conf/ext/aux_newsmailer/';
else
$modulepath=$typopath.'typo3/ext/aux_newsmailer/';

// Defining circumstances for CLI mode:

define('TYPO3_cliMode', TRUE);

//$BACK_PATH = '../../../../typo3/';
define('TYPO3_mainDir', 'typo3/');
define('PATH_thisScript',$typopath.'typo3/typo3');
define('TYPO3_MOD_PATH', $modulepath.'/mailer/');
// Include init file:
require($typopath.'typo3/init.php');
require($typopath.'typo3/sysext/lang/lang.php');

$LANG=t3lib_div::makeInstance('language');
$LANG->init('default');


require($modulepath.'mod1/class_auxnewsmailer_core.php');


$mailer=new tx_auxnewsmailer_core;
$mailer->init();

$mailer->batch($argv[1],'','');



?>

I typed in the PATH=/root/bin in the top of this document and the error returned was
PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/typo3/mydomain/typo3conf/ext/aux_newsmailer/mailer/mailer.sh:3) in /var/www/typo3/mydomain/typo3_src-4.2.1/t3lib/class.t3lib_userauth.php on line 278
# 7  
Old 09-16-2008
Quote:
Originally Posted by Nightowl
I dont think any of the variables are actually used or I just dont get it Smilie

Here is the shell script written in php:

#! /usr/bin/php -q
<?php
...
?>
I typed in the PATH=/root/bin in the top of this document and the error returned was
PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/typo3/mydomain/typo3conf/ext/aux_newsmailer/mailer/mailer.sh:3) in /var/www/typo3/mydomain/typo3_src-4.2.1/t3lib/class.t3lib_userauth.php on line 278

That's a PHP script, not a shell script.

You cannot use shell syntax in PHP.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script fails to run properly when run from CRONTAB

Hello all, I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly. My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Discussion started by: rusman
12 Replies

2. Shell Programming and Scripting

Email body not formatted with html and sendmail

Hi All, I am trying to send the contents of a file as email body. I am using html email and sendmail option of unix. I am using the below piece of code for the same : #!/usr/bin/ksh export MAILTO="email@domain.com" export SUBJECT="Report" export BODY="file_directory_path/test_file.txt"... (1 Reply)
Discussion started by: rockygsd
1 Replies

3. UNIX for Dummies Questions & Answers

Script does not run from a user specific cronjob.

Hello, I have two crontabs, one for the root and one for another user. There is a script in my configurations that has to send a email. The script works and sends the emails when I run it by hand with either the root or the user, and when I program it in the root's crontab. But! It does not... (3 Replies)
Discussion started by: Tralaraloro
3 Replies

4. UNIX for Dummies Questions & Answers

Script not running through Cronjob

Hi, I have a .ksh script which updates the database. The script is running fine manually but it is not running through cron.All the file permissions are fine. The script contents are as below: #!/usr/bin/ksh ddate=`date +%Y%m%d` echo $ddate nohup sqlplus crm/crm @db_state_sync.sql >>... (3 Replies)
Discussion started by: shivangi
3 Replies

5. Shell Programming and Scripting

Script to Alert a file and sends an email

Hello All, I need a script which alerts me when a files arrive in a directory. I don't need every file. but i need some specific pattern file. And i need to get automatic email gettin as an alert For Example: /a/b/c/ : directory format of file should take regualr expression or manually... (2 Replies)
Discussion started by: krux_rap
2 Replies

6. AIX

My script didn't run every run every minute at cronjob

In my cronjob, I would like to schedule my script.sh to run every minutes. I crontab -e and have in line below but it didn't seems to run at all. * * * * * script.sh When I run it manually, I can run it. Is that anything wrong with the above line? If I change it to something like below,... (4 Replies)
Discussion started by: ngaisteve1
4 Replies

7. UNIX for Dummies Questions & Answers

BASH script that sends text message or email

Hi, I have a BASH shell script that batch processes data. I often start this script before I leave to go home for the day, and leave it processing over night. It has come to my attention that it would be very useful for me to add the capability of making the script notify me about certain things... (2 Replies)
Discussion started by: msb65
2 Replies

8. Shell Programming and Scripting

write the script to get the file size and sends an email

hi all Anybody have an idea to write the script to get the file size and sends an email when file size increse more than 10mb. thanks (10 Replies)
Discussion started by: s_linux
10 Replies

9. UNIX for Dummies Questions & Answers

cronjob to run perl script

Hi all Recently i had finished a perl script. When i run manually, the script work fine. But when i wanted to put the script in cron, it didn't get the same output as it run manually. I felt that it only execute the script until certain line then it stop as i see most of the related files didn't... (6 Replies)
Discussion started by: AirWalker83
6 Replies

10. Shell Programming and Scripting

Shell script not running thru Cronjob

Hi I have a shell script, it run ok if executed from the path it is located at but doesnot run when the same is tried through cron-job. can someone help me please. regards gaurav shrinivas Email address removed (8 Replies)
Discussion started by: gauravshrinivas
8 Replies
Login or Register to Ask a Question