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
# 8  
Old 09-17-2008
According to different articles on the web, its still a shell script even though its written in php or are they wrong?

I guess I can conclude it has nothing to do with the environment variables after all?
# 9  
Old 09-17-2008
They are quite wrong. It would be interesting to get links to those different articles.
# 10  
Old 09-17-2008
# 11  
Old 09-17-2008
The point of that article is that you can use PHP to write other things than web pages. If you put #!/usr/local/bin/php -q as the first line of the script, you can use PHP as a regular command-line scripting language. Page 5 of the article explains how you can mix PHP and sh in the same file by embedding a PHP script inside a bash script, or vice versa; but that still doesn't mean you can mix them freely as if they were the same language.

(The author seems to fail to realize that he could single-quote the here document so that he would not have to backslash-escape the variable names in the embedded PHP script:

Code:
#!/bin/bash
echo This is the Bash section of the code.

/usr/local/bin/php -q << 'EOF'
<?php
	$myVar = "PHP";
	print("This is the $myVar section of the code.\n");
?>
EOF

The same techniques are routinely used for embedding sed or awk or Perl or SQL inside shell scripts.)

Last edited by era; 09-17-2008 at 03:58 AM.. Reason: Found page 5 of the article; note on single-quoting HERE doc
# 12  
Old 09-17-2008
Thank you, but with lines like "While PHP as a shell script..." its easy to get confused right?

Anyway, we are getting side tracked here. We have concluded that its not a real shell script, so the shell environment variables are not really important and can't cause the problem.
# 13  
Old 09-17-2008
The environment that the PHP script receives might very well still be the problem. You can create a sh wrapper to set up things the way you like, and invoke that from cron.

Code:
#!/bin/sh
PATH=/ick/y/poo:$PATH
export PATH
/path/to/mailer.php

# 14  
Old 09-17-2008
I dont know what a sh wrapper is, can you explain? Do I need to create a new file, fx wrapper.sh and insert code like the sample in your post and the call that script before my other script?
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