!!blue Posted January 13, 2004 Posted January 13, 2004 Hi all, I found some code to run as what I'm assuming is a "cronjob" from How to limit comments.... The code is: > #!/usr/bin/perl use DBI; my $dbname = 'DATABASENAME'; my $hostname = 'localhost'; # Change this if the db is on another box my $dbuser = 'DBUSER'; my $dbpass = 'DBPASS'; $dbh=DBI->connect("dbi:mysql:database=$dbname;host=$hostname", $dbuser, $dbpass); $dbh->do("update mt_entry set entry_allow_comments='0' where entry_created_on < date_sub(NOW(),interval 7 day)"); It disables comments on MT entries more than 7 days old. Can I use this? How do I make this work? Do I have to save it as a certain type of file & upload it to my site? Or do I have to go thru CPanel to implement this? Also, how can I find out my password to the database? I usually use the same ones but I want to find out for sure. thanks, !!blue Quote
brian Posted January 13, 2004 Posted January 13, 2004 Okay, let me see if I can walk you through setting up a Cron Job if you have never done it before. First, take that code, and save it to a file, and that can go anywhere, in your root home directory, in the public_html, wherever. Call it whatever you would like to call it, as the name doesn't matter. Next, go to your control panel (The CPanel, not in MovableType) and click on Cron Jobs. From there, select standard. You will select the minute you want to run it (Typically I do it on 00) then the hour (Usually for me, that's run at 0) then the days you want to run it (Every day typically for me at least) Then every month, and every weekday. Basically that would run the script at Midnight of every day. Then, for the commandline, you would want to use 'perl <path to directory>' and also enter an email address to get notifications, in case something goes wrong. Now, to find out what database, and password you used, go into the directory you put MovableType in, and open up the config.cfg (I think that's what it's called, the file you edit at the beginning to set up the databases) and there you can get the database. And, then open up the file mt-dbpassword.cgi (Again, I believe that's the name of the file) the one that you used when you setup the password, and there's your password. As always, if you need any help, or more of a walkthrough, PM me... Quote
!!blue Posted January 15, 2004 Author Posted January 15, 2004 (edited) Absolute greek to me! Got the following error in my email from the cron job: DBI connect('database=DATABASENAME;host=HOSTNAME','LOG-IN',...) failed: Access denied for user: 'LOGIN@,HOSTNAME' to database 'DATABASENAME' at /home/...../rmvComm.pl line 10 Can't call method "do" on an undefined value at /home/..../rmvComm.pl line 12. I've bolded code I removed but I'm positive my databasename, login, and password are correct because I can view it under CPanel > MySQL Account Maintenance and I've re-checked the password. The original perl code is in my first post. So what does this error mean and how do I fix it? thanks, !!blue Edited January 15, 2004 by !!blue Quote
DarqFlare Posted January 15, 2004 Posted January 15, 2004 Hey Blue... If you want, I can write up a PHP script fr you that should do the same thing. Quote
DarqFlare Posted January 15, 2004 Posted January 15, 2004 ><? $host = "localhost"; $user = "website_user1"; $pass = "tutti_frutti"; $db = "website_db1"; $Link = mysql_connect($host, $user, $pass); mysql_select_db($db); mysql_query("update `mt_entry` set `entry_allow_comments`='0' where `entry_created_on` < date_sub(NOW(), interval 7 day)"); mysql_close($Link); ?> Try saving that as like "cronfile.php" then add the following cron job to your crons (This is using the Advanced interface): >0 0 * * * GET http://www.yoursite.com/path/to/cronfile.php Let me know if that works. Quote
!!blue Posted January 15, 2004 Author Posted January 15, 2004 (edited) Thanks Robert! All I'd have to do is save it as the same file name of the current script & upload it right? Yet another reason why: Rock Sign I should learn some of these languages; so much easier/lazier to just find free scripts online and use them. Then I couldn't complain when I can't troubleshoot them At least I know where to come for help! thanks, !!blue [edit]i'll save it as you say & go from there[/edit] Edited January 15, 2004 by !!blue Quote
charle97 Posted January 15, 2004 Posted January 15, 2004 david raynes made a closing comments script. Quote
arvind Posted January 16, 2004 Posted January 16, 2004 but with mt's new iplementations of redirecting all spam scripts and mt-blacklist etc. etc. etc. I see no reason why you would want to do this. Some people have actually left nice comments on older posts of mine but anyways just a thought ! Quote
!!blue Posted January 16, 2004 Author Posted January 16, 2004 Thanks, but....this is something I have to do manually every day? It works, but I don't wanna have one more thing to add to my list of daily duties. Shoulda known tho, there are prolly plug-ins for everything. later, !!blue Quote
charle97 Posted January 16, 2004 Posted January 16, 2004 but with mt's new iplementations of redirecting all spam scripts and mt-blacklist etc. etc. etc. I see no reason why you would want to do this. Some people have actually left nice comments on older posts of mine but anyways just a thought ! mt-blacklist and ip banning/throttling won't stop the current wave of comment flooding. i've seen a script with time delays between floods. i've also seen a script that can beat james seng's security code plugin. the bad guys are at least on par with the current methods of fighting comment spamming. they'll probably match anything that comes out to stop them. closing comments after a certain period is a good way to control the threat. Quote
!!blue Posted January 17, 2004 Author Posted January 17, 2004 So blue, what did you decide to do? I decided to go with the php script since it's set to run automatically and I don't have to remember to run it every day. Thanks!! I installed it yesterday and haven't gotten any emails yet. I'll check my entries over the next few days to see if it's working. I've been reading in other blogs of this so-called "comment spam" and other such problems...so I'd rather be safe then sorry. thanks again, !!blue Quote
DarqFlare Posted January 17, 2004 Posted January 17, 2004 K. If you have any problems with the PHP script, I'll take a peek and see if there's a way I can get it to work. Quote
!!blue Posted January 19, 2004 Author Posted January 19, 2004 (edited) Robert, I think the PHP script is not working. When I used & ran the MT plug-in, comments were turned off for older entries. But I removed that plug-in and have noticed that the PHP script has not turned off comments for any other entries. Comments are turned on for entries starting Jan 9th to now. But if I count seven days back from today, it should be turned off by Jan 12th or so. How can I troubleshoot? I haven't gotten anything in my email so the script might think it's running correctly. Movable Type did just release an upgrade which I just installed over the weekend and one of the features listed was this: Closing Comments The Allow Comments checkbox has been turned into a three-item selection menu: Open, None, or Closed. Open and None are the same options that you had in previous versions of Movable Type. Closed allows you to leave up old comments but turn off new comments by removing the comment form from the page. If you have an old entry where you want to leave the comments up, for example, but don't want to allow new ones, this can be useful. To set it up, surround the comment posting form in your template with <MTEntryIfCommentsOpen> tags. For example: ---------------------------------- <MTEntryIfCommentsOpen> <form method="post" ...> ... </form> </MTEntryIfCommentsOpen> ---------------------------------- full documentation can be found here Could this have anything to do with the script not working? But it should've been turning off comments before I did the upgrade anyway. I don't know... thanks, !!blue Edited January 19, 2004 by !!blue Quote
DarqFlare Posted January 19, 2004 Posted January 19, 2004 Hmm... I'm not sure. I rewrote the CGI script into PHP, so it's likely a problem with the MySQL command. I'll do a little research into the MT database and see what I can come up with... Quote
DarqFlare Posted January 19, 2004 Posted January 19, 2004 (edited) Here it is, your newly written PHP script that works -- I tested it on my own blog. ><? $host = "localhost"; $user = "USER" $pass = "PASS"; $db = "DB"; $Link = mysql_connect($host, $user, $pass); mysql_select_db($db); $DB_Result = mysql_query("select `entry_id`, `entry_created_on` from `mt_entry` where `entry_allow_comments`=1"); while($DB_Data = mysql_fetch_row($DB_Result)) { $Entry_ID = $DB_Data[0]; $Entry_Created_On = strtotime($DB_Data[1]); if(($Entry_Created_On + 604800) < time()) { mysql_query("update `mt_entry` set `entry_allow_comments`='0' where `entry_id`='$Entry_ID'"); } } mysql_close($Link); ?> Edited January 19, 2004 by TCH-Robert Quote
!!blue Posted January 19, 2004 Author Posted January 19, 2004 I've uploaded the new file with the same name and it doesn't work (I changed the time in the crontab), but I'm going to check it again tomorrow and let u know. thanks, !!blue Quote
DarqFlare Posted January 19, 2004 Posted January 19, 2004 Augh. lol... Well, this one worked with me... No wonder. There's a new MT version. Well, the script I wrote up works with 2.65, once I upgrade my blog to 2.66, I'll get it working with that version. Sorry, heh... Quote
!!blue Posted January 20, 2004 Author Posted January 20, 2004 LOL, that is funny! Allright, cool, I'll wait & see... later, !!blue ps: i seriously gotta learn some PHP Quote
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.