wmguk Posted February 18, 2009 Share Posted February 18, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/ Share on other sites More sharing options...
wmguk Posted February 18, 2009 Author Share Posted February 18, 2009 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'"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765631 Share on other sites More sharing options...
allworknoplay Posted February 18, 2009 Share Posted February 18, 2009 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' "; Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765634 Share on other sites More sharing options...
wmguk Posted February 18, 2009 Author Share Posted February 18, 2009 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!! Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765643 Share on other sites More sharing options...
wmguk Posted February 18, 2009 Author Share Posted February 18, 2009 hmmmm, ok i have a cron job set up to run this: /var/www/vhosts/domain.co.uk/httpdocs/admin/scripts/cron.php however I get the error: PERMISSION DENIED.... how can i get the php to run? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765646 Share on other sites More sharing options...
premiso Posted February 18, 2009 Share Posted February 18, 2009 I would move it outside of the webfolder, use PHP CLI to run it and make sure it has executable permissions (I believe that is needed by owner, doubt it is needed by public). Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765649 Share on other sites More sharing options...
wmguk Posted February 18, 2009 Author Share Posted February 18, 2009 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'"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765651 Share on other sites More sharing options...
wmguk Posted February 18, 2009 Author Share Posted February 18, 2009 also ive tried changing localhost to the ip address.... same error though.... Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765655 Share on other sites More sharing options...
premiso Posted February 18, 2009 Share Posted February 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765656 Share on other sites More sharing options...
wmguk Posted February 18, 2009 Author Share Posted February 18, 2009 ah i see! Thank you for your help - Googling now! This is my first cron job script! Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765658 Share on other sites More sharing options...
wmguk Posted February 18, 2009 Author Share Posted February 18, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765683 Share on other sites More sharing options...
wmguk Posted February 19, 2009 Author Share Posted February 19, 2009 lol, ok ok, so its done now! Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765684 Share on other sites More sharing options...
premiso Posted February 19, 2009 Share Posted February 19, 2009 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.) Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765685 Share on other sites More sharing options...
wmguk Posted February 19, 2009 Author Share Posted February 19, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765688 Share on other sites More sharing options...
premiso Posted February 19, 2009 Share Posted February 19, 2009 Yep, you just have to look into mysql and shell scripting. Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765689 Share on other sites More sharing options...
wmguk Posted February 19, 2009 Author Share Posted February 19, 2009 cool, thank you for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/145824-solved-creating-a-php-script-to-log-everyone-off-by-cron-job/#findComment-765691 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.