Topic: CRON job script to download emails from imap server to local database - bat file programming issue?? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=30786" title="Pages that link to Topic: CRON job script to download emails from imap server to local database - bat file programming issue?? (Page 1 of 1)" rel="nofollow" >Topic: CRON job script to download emails from imap server to local database - bat file programming issue?? <span class="small">(Page 1 of 1)</span>\

 
paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

posted posted 01-25-2009 09:17

OK so Im following on the last thread here - well I got my system all set to read from a database the emails. The tricky part now is downloading the emails to the database in the first place. However I tried a few options and all of them have some issues.

Option 1: Creating a php script that would download the whole emails and write to a database.

This seemed ok and in theory works quite well when you call the script from a browser window. However inorder to execute it as a standalone script by php.exe as a scheduled task is more complex as I found out the hard way that to execute a php scirpt in this way would require coding the script alot differently than how you would normally code it.

So the other idea was to create a batch process that calls opens internet explorer on the server and thus it would execute the script there and every 3 minutes we would call the batch file through a scheduled task to keep checking for and downloading new emails - dirty but in theory it works. However I think there is something wrong with my batchfile - the thing is that i dont want a new instance of internet explorer to be opened every time the bat file is run. so my batch file is kinda coded like this:

killtask 'path to iexplorer'
path_to_Iexplorer url_of_script
@echo off
cls
exit

If I double click the bat file myself every now and then it does its job however if I set it as a stupid scheduled task - it runs once and then every increments later - nothing happens... I mean whats going on here man I really need to find out whats wrong here.. or are there other solutions to this kind of problem.. I just need an automated way to download from an imap server into a database ...

reisio
Paranoid (IV) Inmate

From: Florida
Insane since: Mar 2005

posted posted 01-25-2009 10:02

http://cygwin.com/
http://cygwin.com/packages/fetchmail/
http://cygwin.com/packages/cron/

paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

posted posted 01-25-2009 11:44

Uh how do I make this do what I want? I want to download emails and then ENTER then into my database ..

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 01-25-2009 15:07
quote:

paritycheck said:

If I double click the bat file myself every now and then it does its job however if I set it as a stupid scheduled task - it runs once and then every increments later - nothing happens




This can be caused by a couple of different reasons. The first that comes to mind is that the login that you used for the scheduled task does not have rights to run a script when logged off. If you go to "Administrator Tools" -> "Local Security Settings" -> "user Rights Assignment" and look for the entry "Log on as Batch job" and "Log on as Service". Make sure you use the username listed there as the user for running the script.

The second thing that comes to mind is that one of the programs that your are calling in your script is not set as an environment variable.

Later,

C:\

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-25-2009 15:29
quote:
This seemed ok and in theory works quite well when you call the script from a browser window. However inorder to execute it as a standalone script by php.exe as a scheduled task is more complex as I found out the hard way that to execute a php scirpt in this way would require coding the script alot differently than how you would normally code it.



What in the world are you talking about? You loose a handful of variables that aren't releveant outside of a http connection, but otherwise the script will run very much the same.

Option 2:
Use lynx. Or Wget. Or just anything but a 'batch scripted internet exploder' (where you kill all the I windows afterwards?!).
Then at least you don't need a desktop for the user running to do a simple http request.

paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

posted posted 01-25-2009 15:50
quote:

Tyberius Prime said:

What in the world are you talking about? You loose a handful of variables that aren't releveant outside of a http connection, but otherwise the script will run very much the same.



Huh.. then how come I keep getting weird include errors when I try to run my script from the cmd line...I mean can I include external files in my php script and get it to run properly from a batch file ...

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-26-2009 11:14

How are you determining the include paths?

paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

posted posted 01-26-2009 22:49

Well I got this figured out to run from explorer but the thing is that this is a temporary solution. The issue is that we need a permanent scalable solution that would download emails from an IMAP server. Right now we have one script that does the downloading called by a scheduled task. Now the issue is that we want to launch our product such that lets say a new user signs up to use this website - it would require that a scheduled task be set up to download the users emails into his database as we plan on having separate databases for users. Is there anyway to like automate this part i.e. creation of cron or scheduled tasks in this fashion? Or is there a better way to do this?

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-27-2009 09:31

You don't need seperate scripts for that. Just one script that correctly closes and opens database connections.

paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

posted posted 01-27-2009 10:09

Well teh thing is that this woudl be running as a daemon - I want to know is it possibel to create a cron job dynamically ? Liek lets say when a user signs up or so..

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-27-2009 12:39

Please learn to type 'the' . I know, we're all in a hurry, but it annoys me to no end.

Also, I have a feeling you don't think carefully enough about my responses.
You do not need several cron jobs. You simply have one that can write
to any database necessary, using php->mysql_connect and php->mysql_close



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu