XDQ的笔记本

Powershell 操作 windows更新

 •  Filed under powershell, windows

定义更新搜索

$Criteria = "IsInstalled=0 and Type='Software'"

搜索可用的更新

$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$SearchResult = $Searcher.Search($Criteria).Updates

下载更新

$Session = New-Object -ComObject Microsoft.Update.Session
$Downloader = $Session.CreateUpdateDownloader()
$Downloader.Updates = $SearchResult
$Downloader.Download()

安装更新

$Installer = New-Object -ComObject Microsoft.Update.Installer
$Installer.Updates = $SearchResult
$Result = $Installer.Install()

检查是否需要重启

$Result.rebootRequired

PS脚本

function log($str){
    Write-Host $str
}

#Define update criteria.
$Criteria = "IsInstalled=0 and Type='Software'"

#Search for relevant updates.
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$SearchResult = $Searcher.Search($Criteria).Updates
$MissingPatches = @($SearchResult).length
log("$($MissingPatches) patches found")
$SearchResult | select Title,IsBeta,IsHidden,IsInstalled,MsrcSeverity | Format-Table -AutoSize

if($MissingPatches -gt 0){
    #Download updates.
    log("download updates")
    $Session = New-Object -ComObject Microsoft.Update.Session
    $Downloader = $Session.CreateUpdateDownloader()
    $Downloader.Updates = $SearchResult
    $Downloader.Download()

    #Install updates.
    log("install updates")
    $Installer = New-Object -ComObject Microsoft.Update.Installer
    $Installer.Updates = $SearchResult
    $Result = $Installer.Install()

    $Result
    #Reboot if required by updates.
    if($Result.rebootRequired){
        log("Reboot required")
    }else{
        log("Reboot not required")
    }
}else{
    log("no patch found")
}

robocopy

 •  Filed under windows
ROBOCOPY "\\servername\sharelocation" "\\newservername\newsharelocation" /MIR    /SEC /LOG:location:\nameoflogfile

重置mac appstore缓存

 •  Filed under mac

关闭App Store
使用终端执行

open $TMPDIR../C/com.apple.appstore/

删除打开文件夹下的所有文件

selinux 常用命令

 •  Filed under linux, centos, centos7, selinux

查看是否有被selinux阻挡

sudo cat /var/log/audit/audit.log | grep denied

boolean

查看boolean状态

sudo sestatus -b

sudo sestatus -b | grep -i sendmail

设置boolean

sudo setsebool -P $boolean名 $1或0

常用boolean

boolean名 意义
httpd_can_network_connect 允许httpd反向代理
httpd_can_sendmail 允许httpd发送邮件

semanager

安装semanager

sudo yum install -y policycoreutils-python

获取系统中的可用label

sudo semanage fcontext -l |grep {SOMETHING}

给文件设置label

sudo semanage fcontext -a -t httpd_sys_content_t /path/to/file
restorecon -v /path/to/file

给文件夹设置label

sudo semanage fcontext -a -t httpd_sys_content_t "/path/to/dir(/.*)?"
restorecon -R -v /path/to/dir