Jump to content

[SOLVED] creating a php script to log everyone off by CRON JOB


Recommended Posts

Hey Guys,

 

I'm running a small site, and the office closes at 6pm so I want to run a cron job at 6.01pm to do a simple script.

 

Basically the DB has a users table, and one field is called "online"... I need to change this for all users in the table to "off"

 

I can get access to my server to set a cron job, but how do i make the script to set all users online=no?

 

Any thoughts?

 

 

hahaha,

 

ok, scrub that...

 

just did a simple

 

<?
include ($_SERVER['DOCUMENT_ROOT'] . "/admin/scripts/scriptheader.php");

$sql="SELECT * FROM users"; 

$result=mysql_query($sql); 
while($row = mysql_fetch_array($result)) 
{
mysql_query("UPDATE users SET online = 'no'");
}
?>

Hey Guys,

 

I'm running a small site, and the office closes at 6pm so I want to run a cron job at 6.01pm to do a simple script.

 

Basically the DB has a users table, and one field is called "online"... I need to change this for all users in the table to "off"

 

I can get access to my server to set a cron job, but how do i make the script to set all users online=no?

 

Any thoughts?

 

 

 

Umm...you just write your script to change the value from ONLINE to OFFLINE??

 

"UPDATE users SET online='offline' ";

 

 

Hey Guys,

 

I'm running a small site, and the office closes at 6pm so I want to run a cron job at 6.01pm to do a simple script.

 

Basically the DB has a users table, and one field is called "online"... I need to change this for all users in the table to "off"

 

I can get access to my server to set a cron job, but how do i make the script to set all users online=no?

 

Any thoughts?

 

 

 

Umm...you just write your script to change the value from ONLINE to OFFLINE??

 

"UPDATE users SET online='offline' ";

 

 

 

yeah sorry - its late here and my brain seems to have left the office already!!

ah, ok, i set it to 777 and i now get this error:

 

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 1: ?: No such file or directory

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 2: =: command not found

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 2: //Host: No such file or directory

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 3: =: command not found

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 3: //MySQL: No such file or directory

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 4: =: command not found

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 4: //MySQL: No such file or directory

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 5: =: command not found

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 5: //Database: No such file or directory

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 7: syntax error near unexpected token `('

/var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php: line 7: `$con = mysql_connect($host,$dbUser,$dbPass) or die(mysql_error());'

 

this is the script:

 

<?
$host = "localhost"; //Host name
$dbUser = "xxx"; //MySQL Username
$dbPass = "xxx"; //MySQL Password
$db = "xxx_xxx" ; //Database name 

$con = mysql_connect($host,$dbUser,$dbPass) or die(mysql_error());
mysql_select_db($db, $con) or die(mysql_error());

$sql="SELECT * FROM users"; 

$result=mysql_query($sql); 
while($row = mysql_fetch_array($result)) 
{
mysql_query("UPDATE users SET online = 'no'");
}
?>

It is because it is just reading out the script to the standard output. You need to process the script using PHP CLI (Command Line Interface). Look it up, I am sure if you google CRON PHP CLI you will get some examples.

ok, the best thing i could find was to SSH in to the server, and use VI to edit crontab...

 

I've added this line:

 

* * * * * lynx -dump http://www.domain.co.uk/admin/scripts/cron.php

and then run crontab crontab from shell, however it still didnt work!!!

 

I'm just so lost! can anyone help me out please?

http://www.devarticles.com/c/a/PHP/PHP-CLI-and-Cron/1/

 

I would suggest against lynx.

 

05 * * * * /usr/bin/php -f /var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php

 

That should run the script, it is better to do it this way, at least in my opinion.  (That runs the script every minutes.)

ah ok, that makes sense now! excellent, so I've now got it to run at 18.01 every day!

 

brilliant thank you...

 

One other thing, is there a way to automatically make an SQL dump of my entire database and set it as a cron job to save to a certain location on my webserver?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.