Jump to content

[SOLVED] Remote Server Access


ainoy31

Recommended Posts

I need to check disk space on a remote server from my web application.  I have tried this piece of code:

 

$access = "ssh user@server-ip-address df -k";

$data = shell_exec($access);

 

If nothing prints out.  I know there is the disk_total_space("/") function but since this is on a remote server.  Much appreciation on any suggestions. AM

 

 

Link to comment
Share on other sites

You can not do this directly, you need to go by a script on your remote server who retrieves that specific piece of information.

 

On your remote server you put this file:

<?php
print disk_total_space('/');
?>

 

On your server you then do:

<?php
$diskspace = file_get_contents('http://domain/path/to/file/php', 'r'); // assuming your server allows to read remote files
echo $diskspace;
?>

Link to comment
Share on other sites

i set this up as a cron job.  such as the following in a php file:

 

$space = shell_exec("ssh (hostname or ip address) df -k | grep sda3 | awk '{print $5}'");

 

this will return the usage in percentage.  Hope this helps someone else out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.