共用方式為


在Linux上使用 Anacron 與 適用於端點的 Microsoft Defender 排程防病毒軟體掃描

適用於:

  • 伺服器的 適用於端點的 Microsoft Defender
  • 伺服器方案 1 或方案 2 的 Microsoft Defender
  • Microsoft Defender 防毒軟體

若要執行 Linux Microsoft Defender 防病毒軟體掃描,請參閱支援的命令

系統需求

請參閱下列在Linux上 Microsoft Defender端點中排程 Microsoft Defender 防病毒軟體掃描所需的系統需求。

  • Linux 發行版和版本:Red Hat Enterprise Linux 7.2 或更新版本。
  • 必須啟用核心中的 FANOTIFY 選項。

另請參閱Linux上 適用於端點的 Microsoft Defender的必要條件。

在 Red Hat Linux 中排程 Microsoft Defender 防病毒軟體掃描

您可以排程 cron 作業,依排程起始 Microsoft Defender 防病毒軟體掃描。 如果裝置一律啟動並執行,此程式就可正常運作。

但是,如果Linux裝置在cron排程期間關閉或離線,則不會執行掃描。 在這些情況下,您可以使用 anacron 來讀取時間戳,並尋找最後執行的作業。 如果裝置在排程的cron作業期間關閉,則必須等到下一個排程的時間。 使用 anacron,系統會偵測上次執行掃描的時間。 如果裝置未執行cron作業,則會自動啟動它。

在 Red Hat Linux 中排程 Microsoft Defender 防病毒軟體掃描

使用下列步驟來排程掃描:

  1. 使用 PuTTY 連線到 RedHat 伺服器。

  2. 編輯 anacron 檔案,如下所示:

    vi /etc/anacron
    
  3. 檢閱和編輯您的 Anacron 檔案,其中包含下列資訊:

    # /etc/anacrontab: configuration file for anacron
    # See anacron (8) and anacrontab (5) for details.
    SHELL=/bin/sh
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    RANDOM_DELAY=45
    # Anacron jobs will start between 8pm and 11pm.
    START_HOURS_RANGE=20-23
    # delay will be 5 minutes + RANDOM_DELAY for cron.daily
    

    請注意檔案中的下列專案:

    • Shell 稱為 /bin/sh,而不是 。/bin/bash 當您設定作業時,請記住這一點。
    • RANDOM_DELAY 描述作業的最長時間,以分鐘為單位。 此值可用來位移作業,因此不會同時執行太多作業。 使用此延遲非常適合用於 VDI 解決方案。
    • START_HOURS_RANGE 描述執行作業的時間範圍。
    • cron.daily 將 描述 1 為作業執行頻率所需的天數。 '5 是裝置重新啟動后,aacron 等候的延遲分鐘數。
  4. 使用下列命令檢閱您的 Anacron 作業:

    ls -lh /etc/cron*
    

    您應該看到類似下列螢幕快照所示的資訊:

    範例 Anacron 作業 Linux。

    下列程式代碼範例提供更詳細的檢視:

    [root@redhat7 /] # ls -lh /etc/cron*
    - rw - - - - - - -.  1   root    root    0   Nov 30 2021 /etc/cron.deny
    - rw - r - - r - -.  1   root    root    451 Dec 27 2013 /etc/crontab
    
    /etc/cron.d:
    total 28k
    - rw - r - - r - -.  1   root    root    128 Nov 30  2021    0hourly
    - rw - r - - r - -.  1   root    root    121 Feb 25  18:11   omilogotate
    - rw - r - - r - -.  1   root    root    118 Feb 25  18:14   omsagent
    - rw - r - - r - -.  1   root    root    79  Feb 25  18:15   OMSConsistencyInvoker
    - rw - r - - r - -.  1   root    root    108 Nov 9   2021    raid-check
    - rw - r - - r - -.  1   root    root    135 Jun 1   22:35   scxagent
    - rw - - - - - - -.  1   root    root    235 Jan 20  2020    sysstat
    
    /etc/cron.daily:
    total 24k
    - rwxr - xr - x. 1   root    root    127 Jun 14  16:49    avscandaily
    - rwx - - - - - -.   1   root    root    219 Aug 7   2019 logrotate
    - rwxr - xr - x. 1   root    root    618 Jul 10  2018     man-db.cron
    - rwx - - - - - -.   1   root    root    208 Nov 9   2017    mlocate
    - rwx - - - - - -.   1   root    root    558 Apr 18  19:03   rhsmd
    - rwxr - xr - x. 1   root    root    114 Apr 8   2021    rhui-update-client
    
    /etc/cron.hourly:
    total 8.0k
    - rwxr - xr - x. 1   root    root    392 Nov 30  2021    0anacron
    - rwxr - xr - x. 1   root    root    131 Jun 14  17:05   update
    
    /etc/cron.monthly:
    total 0
    - rwxr - xr - x. 1   root    root    0   Jun 14  17:47   mdatpupdate
    
    /etc/cron.weekly:
    total 0
    

    /etc/cron.d忽略目錄,請改為檢閱 /etc/cron.daily, hourly, monthly, and weekly

  5. 若要排程每周的防病毒軟體掃描,您可以在目錄下 /etc/cron.weekly (作業) 建立檔案。

    cd /etc/cron.weekly
    
    vi mdavfullscan
    
    Press Insert
    

    每周防病毒軟體掃描

    #!/bin/sh
    set -e
    echo $(date) "Time Scan Begins" >>/logs/mdav_avacron_full_scan.log
    /bin/mdatp scan full >> /logs/mdav_avacron_full_scan.log
    echo $(date) "Time Scan Finished" >>/logs/mdav_avacron_full_scan.log
    exit    0
    ~
    
    Press Esc
    
    Type: wq!
    
  6. 變更檔案許可權,以允許使用下列命令來執行檔案:

    Chmod 755 mdavfullscan
    
    ls -la
    

    7.變更檔案許可權

    [root@redhat7 cron.weekly]# ls -la
    total    16
    drwxr - xr - x.  2   root    root    26  Jun 14  19:19   .
    drwxr - xr - x.  85  root    root    8192    Jun 14  19:01   ..
    - rw - r - - r - -.  1   root    root    128 Jun 14  19:19   mdavfullscan
    [root@redhat7 cron.weekly] # chmod 755 mdavfullscan
    [root@redhat7 cron.weekly] # ls -lh
    total 4. 0k
    - rwxr - xr - x. 1   root    root    128 Jun 14  19:19   mdavfullscan
    [root@redhat7 cron.weekly] #
    
  7. 使用下列命令來測試每周的 Anacron 作業:

    ./mdavfullscan
    
  8. 使用下列命令來確認工作已成功執行:

    cat /logs/mdav_avacron_full_scan.log
    

    確認作業已執行

    [root@redhat7 cron.weekly] # cat /logs/mdav_avacron_full_scan.log
    Tue Jun 14 20:20:44 UTC 2022 Time Scan Begins
    Scan has finished
        66547 file(s) scanned
        0 threat(s) detected
    Tue Jun 14 20:20:50 UTC 2022 Time Scan Finished
    [root@redhat7 cron.weekly] #
    

另請參閱

提示

想要深入了解? Engage 技術社群中的Microsoft安全性社群:適用於端點的 Microsoft Defender 技術社群。