php-cli for system admin?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • walterbyrd

    php-cli for system admin?

    For real, could php-cli be useful for system admin tasks?

    I doubt php-cli will ever match perl, or python, for a sys admin
    scripting language. But, does php-cli come close enough to the sys
    admin power of those languages that php might actually be useful for
    admins?

    As far as I know, nobody seriously uses php for a shell scripting
    language. Is that just because perl is so well established? Or because
    php doesn't have the power?

    I have not been able to find much about using php for system admin, or
    using php-cli at all. I googled around, but all I find were "hello
    world" type examples.

  • Dikkie Dik

    #2
    Re: php-cli for system admin?

    For real, could php-cli be useful for system admin tasks?

    Theoretically yes, but in practise...
    I doubt php-cli will ever match perl, or python, for a sys admin
    scripting language. But, does php-cli come close enough to the sys
    admin power of those languages that php might actually be useful for
    admins?
    I am afraid that all depends on the OS and off course what you want to do.
    As far as I know, nobody seriously uses php for a shell scripting
    language. Is that just because perl is so well established? Or because
    php doesn't have the power?
    I *did* try it. There are things that should be done on a web server
    with scripts, and PHP is the only language that is guaranteed to exist
    on both the development machine and the servers the site has to be run
    on. And PHP tends to be pretty OS-inspecific, so I wanted at least some
    testscripts done in PHP. There are a few drawbacks:

    - Parameters are not passed, unless you specifically call the language
    interpreter. so "testdir.ph p somedir" will not see the somedir
    parameter, but "C:\PHP\php .exe testdir.php somedir" will. I think a
    sysadmin was able to fix this under linux, but I do not know how.

    - When running windows, created directories are read-only. I had to
    shell out to dos just to create a directory in a useful way. Off course,
    all OS-independence stops here. Under linux, you can give the create
    flags, but these are ignored in windows.
    ..., but all I find were "hello world" type examples.
    Well, that will work, but the rest may requires som more testing, I'm
    afraid.

    Best regards

    Comment

    • Jerry Stuckle

      #3
      Re: php-cli for system admin?

      Dikkie Dik wrote:
      >For real, could php-cli be useful for system admin tasks?
      >
      Theoretically yes, but in practise...
      >
      In practice, yes. I do a lot of CLI scripts in PHP and they work quite
      well.

      >I doubt php-cli will ever match perl, or python, for a sys admin
      >scripting language. But, does php-cli come close enough to the sys
      >admin power of those languages that php might actually be useful for
      >admins?
      >
      I am afraid that all depends on the OS and off course what you want to do.
      >
      I find I can do anything in PHP that I can do in the other languages.
      Is there something you've found you can't do in PHP that you can in Perl
      or Python?
      >As far as I know, nobody seriously uses php for a shell scripting
      >language. Is that just because perl is so well established? Or because
      >php doesn't have the power?
      >
      I *did* try it. There are things that should be done on a web server
      with scripts, and PHP is the only language that is guaranteed to exist
      on both the development machine and the servers the site has to be run
      on. And PHP tends to be pretty OS-inspecific, so I wanted at least some
      testscripts done in PHP. There are a few drawbacks:
      >
      A lot of people use PHP for a shell scripting language.
      - Parameters are not passed, unless you specifically call the language
      interpreter. so "testdir.ph p somedir" will not see the somedir
      parameter, but "C:\PHP\php .exe testdir.php somedir" will. I think a
      sysadmin was able to fix this under linux, but I do not know how.
      >
      I don't know about on Windows (I don't have the file associations set up
      to run them automatically), but they are on Linux. If they aren't on
      your system, your system is broken.
      - When running windows, created directories are read-only. I had to
      shell out to dos just to create a directory in a useful way. Off course,
      all OS-independence stops here. Under linux, you can give the create
      flags, but these are ignored in windows.
      >
      As I said - I don't do them on Windows.
      >..., but all I find were "hello world" type examples.
      >
      Well, that will work, but the rest may requires som more testing, I'm
      afraid.
      >
      Best regards
      But then I also don't do Perl or Python scripts on Windows.

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • 469

        #4
        Re: php-cli for system admin?

        Dont forget, that PHP actually is not only web-based and cli based...
        but GTK2 based ;) so not only yopu can use shell scripts to admin the
        system... but you can do a pretty nice and helpfull visual app with
        php...

        actually i use PHP shell scripting to do remote administrative
        tasks... like http://myhomeserver/scriptsfolder/thisaction... one of
        them, backs up eve3rything (Postgresql, Mysql, webroot) if it needs to
        wake up a service... it will do it backup and shut it down again...
        and then scp me the files... to the pc i am currently on... (Usually
        my laptop, or the house desktop)

        also... setups for Webapps that i've made.... i usually create a lil
        setup for em... so if i sold it, and the client doesnt needs big
        modifications.. . i just... unpack, run... and the script does the
        rest :p


        belive me.. you can even create a filedownloader with php in like 15
        mins... on linux... xD

        Comment

        • Toby A Inkster

          #5
          Re: php-cli for system admin?

          walterbyrd wrote:
          As far as I know, nobody seriously uses php for a shell scripting
          language. Is that just because perl is so well established? Or because
          php doesn't have the power?
          I use it from time to time. Sometimes I use Perl. Sometimes I use other
          things. Depends on what has to be done (some languages are more suitable
          for some tasks) and what kind of mood I'm in.

          --
          Toby A Inkster BSc (Hons) ARCS
          Contact Me ~ http://tobyinkster.co.uk/contact
          Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

          * = I'm getting there!

          Comment

          • Toby A Inkster

            #6
            Re: php-cli for system admin?

            469 wrote:
            Dont forget, that PHP actually is not only web-based and cli based...
            but GTK2 based so not only yopu can use shell scripts to admin the
            system... but you can do a pretty nice and helpfull visual app with
            php...
            And of course, you can use the same backend code for all three interfaces. :-)

            --
            Toby A Inkster BSc (Hons) ARCS
            Contact Me ~ http://tobyinkster.co.uk/contact
            Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

            * = I'm getting there!

            Comment

            • walterbyrd

              #7
              Re: php-cli for system admin?

              Thanks for all the responses.

              FWIW: I did find some decent tutorials on the subect on sitepoint:




              These tutorials go beyond "hello world" but they certainly don't
              compare with the documentation given to using perl, or python, for sys
              admin tasks. For example, there are at least two perl books
              specifically dedicated to perl for sys admin. And at least a few
              chapters in o'reilly books dedicated to using python. I think php
              cookbook dedicates a chapter to php-cli, but again, it hardly compares
              to all the docs I find on using perl for sys admin.

              Comment

              • Jerry Stuckle

                #8
                Re: php-cli for system admin?

                walterbyrd wrote:
                Thanks for all the responses.
                >
                FWIW: I did find some decent tutorials on the subect on sitepoint:
                >


                >
                These tutorials go beyond "hello world" but they certainly don't
                compare with the documentation given to using perl, or python, for sys
                admin tasks. For example, there are at least two perl books
                specifically dedicated to perl for sys admin. And at least a few
                chapters in o'reilly books dedicated to using python. I think php
                cookbook dedicates a chapter to php-cli, but again, it hardly compares
                to all the docs I find on using perl for sys admin.
                >
                So? Just because you don't find books on how to do it doesn't mean it
                can't be done.

                For instance, it could also mean those other languages *need* those
                chapters/books to teach people how to do things, and PHP doesn't.

                I do a lot of sysadmin tasks, but have never needed a PHP book to help
                me with them. Linux admin, yes. Php admin, no.

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • Michael Fesser

                  #9
                  Re: php-cli for system admin?

                  ..oO(walterbyrd )
                  >These tutorials go beyond "hello world" but they certainly don't
                  >compare with the documentation given to using perl, or python, for sys
                  >admin tasks.
                  How do you define "sys admin task"? If something can be done in Perl, it
                  can also be done in PHP. Running a PHP CLI script as root even allows to
                  crash your system if you're not careful. It's just another language with
                  another (IMHO much more readable) syntax, but still as powerful as Perl
                  or Python.

                  Micha

                  Comment

                  • walterbyrd

                    #10
                    Re: php-cli for system admin?

                    So? Just because you don't find books on how to do it doesn't mean it
                    can't be done.
                    But it indicates that it's not as popular, and there as not as many
                    pre-writen scripts. Another indication is the job boards, employers
                    want admins who know perl, or python (usually perl).

                    And please understand, I am not asserting that admin tasks can not be
                    done just as easily with php as perl. I am simply recognizing that
                    perl is much more popular for sys admin, and I'm asking if php could
                    do the same sorts of things.

                    Comment

                    • walterbyrd

                      #11
                      Re: php-cli for system admin?

                      How do you define "sys admin task"?

                      Actually, that is not easy for me to define. I can give examples:

                      - apply an update to 200 servers running the same version of Linux.

                      - remove a user from the LDAP directory.

                      - issue the same command on a series of servers, working from a list
                      of servers in a text file i.e.:

                      ../docommand.php serverlist.txt "command"

                      - shutdown and re-start a process that takes several steps to shutdown
                      and restart. Best if this could be done from the process name.

                      - give me a report of all users who have not logged in within the last
                      seven days.

                      - give me a list users who have more than 100mb of files in their home
                      directories. If a user has less than 100mb of files in their home
                      directory, then set their quota to 100mb.

                      Please don't actually tell me how to do any of that. I'm just
                      wondering if those sorts of things can be done.

                      Comment

                      • Michael Fesser

                        #12
                        Re: php-cli for system admin?

                        ..oO(walterbyrd )
                        >How do you define "sys admin task"?
                        >
                        >Actually, that is not easy for me to define. I can give examples:
                        >[...]
                        >
                        >Please don't actually tell me how to do any of that. I'm just
                        >wondering if those sorts of things can be done.
                        Yep, definitely. If you are able to call system functions you can do
                        absolutely everything. In some cases a particular scripting engine can
                        make things easier by providing pre-built extensions, for example DB
                        access, LDAP or RPCs. For all other things there's at least system(),
                        exec() or something like that to do it "by hand".

                        Micha

                        Comment

                        • 469

                          #13
                          Re: php-cli for system admin?

                          You can also use ssh whithin PHP... and even... create an ajax driven
                          "frontend" that works as a console lol :p

                          Posibilities are innumerable, even you can take screenshots... and if
                          im not mistaken.. take also webcamshots... (FOr the hour-to-be works)

                          On Feb 25, 8:30 pm, Michael Fesser <neti...@gmx.de wrote:
                          .oO(walterbyrd)
                          >
                          How do you define "sys admin task"?
                          >
                          Actually, that is not easy for me to define. I can give examples:
                          [...]
                          >
                          Please don't actually tell me how to do any of that. I'm just
                          wondering if those sorts of things can be done.
                          >
                          Yep, definitely. If you are able to call system functions you can do
                          absolutely everything. In some cases a particular scripting engine can
                          make things easier by providing pre-built extensions, for example DB
                          access, LDAP or RPCs. For all other things there's at least system(),
                          exec() or something like that to do it "by hand".
                          >
                          Micha

                          Comment

                          • Jerry Stuckle

                            #14
                            Re: php-cli for system admin?

                            walterbyrd wrote:
                            >So? Just because you don't find books on how to do it doesn't mean it
                            >can't be done.
                            >
                            But it indicates that it's not as popular, and there as not as many
                            pre-writen scripts. Another indication is the job boards, employers
                            want admins who know perl, or python (usually perl).
                            >
                            And please understand, I am not asserting that admin tasks can not be
                            done just as easily with php as perl. I am simply recognizing that
                            perl is much more popular for sys admin, and I'm asking if php could
                            do the same sorts of things.
                            >
                            Not necessarily. It might mean that it's so simple you don't need
                            complicated scripts to do it.

                            And job boards are also not a good indication. They generally look for
                            things people don't already have available and know about. They aren't
                            going to ask for something they already have, or something they don't
                            know can be done (at least most won't).

                            As I said before, PHP is a perfectly good tool for doing admin tasks.

                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstucklex@attgl obal.net
                            =============== ===

                            Comment

                            Working...