know your tools
I spent some time today trying to write a script to mark all of the spam comments that I’ve gotten over the last few months as spam. I tried to use curl to log in to the blog and delete them, but I kept having trouble hanging on to my session. It seems like if you don’t follow the right sequence of pages, you have to re-validate your session. And the, when you finally have the right sequence figured out, you have to visit more pages than you should. Finally, I realized that I could just edit the messages in bulk, and mark them all as spam. Sure, it took twenty pages of marking, but I finally got it finished.
So the point is, you should always look for an easy way to do things before committing yourself to the hard way.
But hey, if you’re interested, here’s what I was working with:
curl --cookie-jar /tmp/cj 'http://pillowsopher.com/blog/wp-login.php'
curl -L --cookie-jar /tmp/cj 'http://pillowsopher.com/blog/wp-login.php' --data 'log=aturley' --data "pwd=$PASSWORD" --data 'rememberme=forever'
curl -L --cookie /tmp/cj --cookie-jar /tmp/cj 'http://www.pillowsopher.com/blog/wp-admin/index.php' --data 'log=aturley' --data "pwd=$PASSWORD"
curl --cookie /tmp/cj --cookie-jar /tmp/cj 'http://www.pillowsopher.com/blog/wp-admin/edit-comments.php' --data 'log=aturley' --data "pwd=$PASSWORD"
Some of the –data arguments are unnecessary, but I’m tried right now, so I don’t feel like figuring out which ones.