MENU

Sudo command php

2
39230
0

I’ve got problem to check and mount disk, because sometimes my unix machine disconnect USB disk, so I want to write script that check last disk and mount it.

But there was a problem to run system command fdisk to return all disks.

So here is solution:

– edit or create file

nano /etc/sudoers

– insert into file

Defaults        env_reset
 
%www-data ALL=(ALL) NOPASSWD: ALL

– exit and save

You also need sudo installed on system !

Now you can execute sudo script with php command exec()

<!--?php $lastLine=exec("sudo fdisk -l",$retVal); ?-->

Have a nice day 🙂

 

 

COMMENTS: 2
  1. October 18, 2012 by kvasar Reply

    ondrej sorry, nemozem si odpustit tento comment, ale taketo nieco dat na web, len ukazuje tvoju nevedomost. to uz si mozes apacha rovno pod rootom spustit 🙂 popremyslaj nad tym.

    • October 18, 2012 by admin Reply

      Ahoj,
      Vdaka za comment, nazivo to nedavam nikde, ale moze to byt potrebne pre interny system. Samozrejme ze dat to nazivo by bolo pekna kravina :). Ale mali sme interny system ktory potreboval taketo veci a tam to nevadilo pretoze to bolo pod VPN a uctovnik nevie ani co je apache.
      Ale este raz vdakaza comment.

Leave a Comment!

Your email address will not be published. Required fields are marked *