PHP Automated Administrivia?
wikinerd asks: "I am sure all of you know what PHP is and many of you may even use it on your websites, like me. Some of you may have read a this article from Linux.com article that gives some examples on how to use PHP to automate your server administration tasks (or to say it with one word: administrivia). I wonder whether there are any Slashdot users that have already used PHP in their administrivia, and what the results are. Is PHP appropriate for this task? If you have written useful PHP scripts, would you consider to publish their source code here? I am sure that posting your scripts can be beneficial to many new (and old) admins, so let's share our work!"
I'm only a system admin because my laptop runs unix, so I'm stuck with the job. I have adopted PHP as my shell scripting language of choice, because I've been doing lots of PHP work, and because (ack) I've gotten older and it's a pain in the ass remembering all the minute differences in syntax between languages that are, for all intents and purposes, the same. fi, anyone? I mean, how fucking cute.
Mostly I've used it for file processing type stuff, where I didn't particularly cared how quickly it ran. I haven't done lots of admin stuff, trying to glue together the results of various commands.
If you're a real sysadmin, you probably want Perl and CPAN. But if you spend your days hacking at websites with PHP, you might as well use the same skills for system scripting.
Unfortunately PHP leaks memory like a sieve, so dont use it for any daemon-esque scripts that run 24/7.
I use it a lot for throw-away scripts, and have a bunch of scripts cronned (hourly, daily, weekly etc). PHP is great in this sort of role if you're already familiar with PHP.
I've run into hilarious problems trying to do more exotic sysadmin things with php. Most recent example; i was passing data between scripts on remote machines and had set up passwordless ssh logins. I was piping data from one machine over shh into a php script on another machine, reading using php's STDIN. Leaked 500 meg in a couple of mins before it was killed. (I only transfered around 50k of data).
Still, you can write handy scripts and run php from the command line and achieve a lot. php -f file.php, or use a #!/usr/bin/php -r shebang and you dont need the php tags round code.
RJ
Last.fm - join the social music revolution
Is PHP aproppriate for this task?
No. You don't even have to tell me what the task is.
I use PHP only to maintain existing PHP applications, never to create new ones. But, sometimes you need to do nightly command-line stuff (like, clean out old archived orders or something). So I do use PHP for that kind of stuff. After all you've already got all the DB access, ORM layer, everything, why not just re-use them? Considering that sad state of databases and integrity constraints today, you probably *must* do it that way otherwise you will get bad data into the database.
But I sure wouldn't use it for sysadmin or anything like that. *shiver*. Stick with a language like Ruby.
Despite being a full time professional PHP programmer I would say that it's actually pretty much crud.
It's interfaces are inconsistent : sometimes ($subject, $predicate) sometimes ($predicate, $subject)
The worst thing that ever happened to it ws the CLI version
Steer clear, it's not worth the hassle
My adivce is to go for mature sys admin tools
There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter