Viewing file: make_quota_backup.php (1.56 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/php5
<?php $passwd="/etc/passwd"; $group="/etc/group";
$user_quota="/home/quota_user.dat"; $group_quota="/home/quota_group.dat";
umask(077);
$fh = fopen($passwd,"r"); $fw = fopen($user_quota, 'w');
while (!feof($fh)) { $line = trim(fgets($fh, 2048)); $a=explode(":",$line); $uid=$a[2]; $gid=$a[3]; $username=$a[0]; if (($username != '') && ($uid >= 1000) && ($uid < 65534)) { $query="quota -u ".$username; unset($result); exec($query, $result); if (isset($result[2])) { $result=explode(" ", trim($result[2])); unset($output); foreach ($result as $a) { if ($a != '') $output=$output.":".$a; } $result=$username.":".$uid.":".$gid.":".$output."\n"; fwrite($fw, $result); } } } fclose($fh); fclose($fw);
$fw = fopen($group_quota, 'w');
$fh = fopen($group,"r"); while (!feof($fh)) { $line = trim(fgets($fh, 2048)); $a=explode(":",$line); $gid=$a[2]; $groupname=$a[0]; if (($groupname != '') && ($gid >= 1000)) { $query="quota -g ".$groupname; unset($result); exec($query, $result); if (isset($result[2])) { $result=explode(" ", trim($result[2])); unset($output); foreach ($result as $a) { if ($a != '') $output=$output.":".$a; } $result=$groupname.":".$gid.":".$output."\n"; fwrite($fw, $result); } } } fclose($fh); fclose($fw);
?>
|