Jump to content

Unix and commands


funguse

Recommended Posts

Hey,

 

I'm currently working on the intranet site for our company and i've been asked to create a site where the status of our unix server is been displayed. at the moment all admins have their own logon using AIX (v4) and using the command topas to display the idle and other info.

 

what i want to do is create we php script that connects to the server using a logon and executing the topas command. i then want to display the idle process (but tahts not that importaint. i'll get to that when i'm able to connect to the server (if thats possbile lol)

Link to comment
Share on other sites

sorry,

 

my question is, how can i connect to the unix server with a specific username and password via a php script (if thats possible at all) and if you can how can you execute certain commands and getting the info back to the intranet server.

Link to comment
Share on other sites

ok here is an update.

 

to test if i can connect to my server via ssh2 im just running this little script but every time i open the file.php my cpu usage goes to 50% (taskmanager says httpd.exe) even when i close the window, when i run it again it goes to 100%.

 

what am i doing wrong? ip of server, username and password are all correct

 

<?php 
echo "line 1";
$connection = ssh2_connect('ip', 23); 

echo "line 2";
ssh2_auth_password($connection, 'user', 'pass'); 

echo "line 3";
$stream = ssh2_exec($connection, 'cd /data/msoft'); 

echo "line 4";
echo $stream;
?> 

 

 

the error message im getting is:

 

 

Warning: ssh2_connect() [function.ssh2-connect]: Unable to connect to 172.19.1.38 on port 22 in C:\www\webroot\test\test.php on line 2

Warning: ssh2_connect() [function.ssh2-connect]: Unable to connect to 172.19.1.38 in C:\www\webroot\test\test.php on line 2

Fatal error: Maximum execution time of 30 seconds exceeded in C:\www\webroot\test\test.php on line 2

 

Link to comment
Share on other sites

What I would do and am somewhat doing right now with perl is.

 

1.) Write a PERL script or BASH script that will run TOPAS and pipe resuts to a file. The problem with TOPAS is kind of messy because every time it refreshes it will write a new section.(It will be very hard to parse)

  - I would find out what you want to identify and display: uptime, processes, diskspace, etc etc

  - Write a bash script that pipes the results to a file every minute and ftp/sftp the file to you webserver. Schedule using a cron job.

  - Write a php webpage that will parse the files from the server.

  - Everytime they refresh the page after 1 minute the status will be updated. This would be minimal on resources for all servers and pretty easy to do. You can even add javascript to the page to refresh every minute.

 

I hope that this helps.

 

Link to comment
Share on other sites

ok i think i've managed to get at least something with telnet

(see code and images)

 

i want to get the value next to idle but dont quite know how i can do that. and also the value does not display on the output (image 2). any one know y that is?

 

 

 

image 1

image 2

 

 

<?php  
$username='root';
$password='sibi123';

$header1=(	
			chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).chr(0x27).chr(0xFF).chr(0xFD).chr(0x01).
			chr(0xFF).chr(0xFB).chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).chr(0x1F).chr(0x00).chr(0x50).
			chr(0x00).chr(0x18).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).chr(0x38).chr(0x34).
			chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).chr(0x45).
			chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0)
		); 

$header2=(	
			chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).chr(0xFC).chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).chr(0xFF).chr(0xFC).chr(0x21)
		);

$fp=pfsockopen("172.19.1.38",23); 

fputs($fp,$header1); 
sleep(1); 
fputs($fp,$header2); 
sleep(1); 

fputs($fp,"$username\r"); 
sleep(1); 
fputs($fp,"$password\r"); 
sleep(1); 
fputs($fp,"\r"); 
sleep(3); 
fputs($fp,"\r"); 
sleep(3); 
fputs($fp,"q \r"); 
sleep(3); 
fputs($fp,"topas \r"); 
sleep(1); 

$output=fread($fp,128); 
$stat=socket_get_status($fp); 
$output.=fread($fp, $stat["unread_bytes"]); 

$output = explode("\n", $output); 
unset($output['0']); 
$output = implode("\n", $output); 

$output = str_replace("\n", "<br>", $output); 
echo $output; 
fclose($fp); 
?> 

 

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.