What is the process for extracting system information from Unix and saving it to an external file for import into a MySQL database using PHP?

To extract system information from Unix and save it to an external file for import into a MySQL database using PHP, you can use shell commands to gather the information and write it to a file. Then, you can use PHP to read the file, parse the data, and insert it into the MySQL database.

<?php
// Execute shell command to gather system information and save it to a file
$system_info = shell_exec('uname -a && df -h && top -n 1');
file_put_contents('system_info.txt', $system_info);

// Read the saved file and parse the data
$system_data = file_get_contents('system_info.txt');

// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Insert system information into MySQL database
$sql = "INSERT INTO system_info (info) VALUES ('$system_data')";
$conn->query($sql);

// Close database connection
$conn->close();
?>