0

I use shell_exec('wmic DISKDRIVE GET SerialNumber 2>&1'); to get serial number of disk drive on window and it's working well.

Now i'm test that on ubuntu and i use echo shell_exec("hdparm -I /dev/sda"); it's empty, nothing shown. How to get serial number in linux thanks

Edit

i fogot 2>&1 but it say /dev/sda: Permission denied ?

DeLe
  • 2,442
  • 19
  • 88
  • 133
  • What do you want to happen if a system has no local disks (you can run Unix entirely off network drives, for example)? Or if it has multiple disks? (Also: I just tried this on my Ubuntu install and the reason it fails for me is that I don't have `hdparm` installed at all...) Do you have control over the server environment? Can you specify that the end-user has to have `hdparm` installed to run your PHP script? – Matt Gibson Mar 09 '14 at 07:36
  • 2
    Leaves to say that hdparm also requires root permissions. – hek2mgl Mar 09 '14 at 07:37
  • 1
    The real question here might be: why? This is quite an unusual requirement for a PHP script. If we know why you feel you want to get the serial number of a hard drive, it's possible we could suggest an alternate, more "normal" way of achieving what you want. – Matt Gibson Mar 09 '14 at 07:40
  • @MattGibson why it is "uncommon" for a PHP script to do that? this part I don't get – hek2mgl Mar 09 '14 at 07:41
  • 1
    @hek2mgl PHP scripts don't normally need detailed information about the hardware of the boxes they're running on. If you're using `shell_exec`, you've pretty much left PHP and entered the realm of wanting to do things that are outside its norms. Sometimes that's quite reasonable, but you rarely see a language designed to serve web pages needing to know the serial number of some random disk in the box it happens to be running on. There's... a marked difference between the abstraction level of the language and the information being requested, I'd say. – Matt Gibson Mar 09 '14 at 07:46
  • @MattGibson I need to manager or store `serialnumber` of disk using `php` and `mysql` – DeLe Mar 09 '14 at 07:52
  • 1
    yes, it's a very unusual requirement. Why does your script care what server it's running on? If the disk fails and you reinstall the app on a different hard disk, will it explode because the numbers no longer match? – sevenseacat Mar 09 '14 at 08:04
  • @sevenseacat but i get `Permission denied`? – DeLe Mar 09 '14 at 10:54
  • see other comments and other comments on the answers for the other question. – sevenseacat Mar 09 '14 at 12:14
  • @sevenseacat i saw all of them, but it don't fix that – DeLe Mar 09 '14 at 12:20
  • @MattGibson From the php man page: `PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.` I personally had often to do with tasks that where related to system programming, in PHP. – hek2mgl Mar 09 '14 at 14:22

0 Answers0