linux


16
Oct 08

How to setup a linux cronjob in 3 steps

Since web apps are executed only after an HTTP request, you may have situations where scripts need to run in the background on a scheduled basis. On Linux, to do this you’ll need to get to know the crontab. The way it works is kind of like an airport. The service is always running, however planes only depart at their scheduled times. The crontab is kinda like that, a daemon that runs constantly in the background and checks once a minute to see if any jobs need to be executed.

Let’s say you have a script located at http://www.acme.com/myscript.php that needs to run the first of every month at 9am. Here’s how you’d set it up:

1. Look for a file in your /etc folder called crontab.
2. You need to install a new crontab job, to do this type crontab -e.
3. Now the tricky part, the syntax:

and here’s how that translates in our example:

0 9 1 * * curl http://www.acme.com/myscript.php

Lets break it down. 0 is for the minute, 9 is the hour – so 9 hours & 0 minutes which is 9am. Day of the month, 1 – easy. We want to do this for every month & week, which is accomplished using the wildcard or * character. Next comes what we want to execute. It’s not enough to just type the URL of the script, you’ll need to use the CURL system function to make the HTTP request for you.

Here is some more information on CURL & Cron jobs for your reading pleasure, hope this tutorial helps!


5
May 08

Sendmail says: stat=Deferred: Connection reset

I have been struggling with this problem for the last 2 days and finally figured out the solution. Your mileage may vary depending on your network configuration but first some background on mine. I have a Lighttpd web server that i am running some PHP mail scripts on. We are trying to use our company’s MTA to relay messages so i had this line in the sendmail.cf file, with 10.0.0.116 being the IP address of our MTA.

define(`SMART_HOST', `10.0.0.116')dnl

Still, things didn’t seem to want to work. My network administrator wasn’t evening seeing the mail attempts on our mail server so the problem was definitely on the webserver.
Turns out (as these things often are) that it was a dumb syntax problem. The following change fixed everything:

define(`SMART_HOST', `[10.0.0.116]')dnl

Hope this helps if you are having a similar problem.


31
Mar 08

Phpmyadmin error: “Cannot start session without errors”

I have been trying to get phpmyadmin working on my Fedora 8 server i’ve been setting up, and struggled for the past day or so on this error:

Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.

Turns out it’s very easy to fix. First thing you’ll want to do is have a look at your error logs. For me this was in /var/log/lighttpd/error.log (i’m using lighttpd instead of Apache). Have a look at your error log and you will probably see errors referencing permission errors writing to your session directory.

Simply chmod 777 that directory and you should be good to go.