¿Ya eres cliente de NinjaOne? Inicia sesión para ver más guías y las últimas actualizaciones.

Script personalizado: Eliminación del agente NinjaOne (MacOS)

Tema

Este script elimina el Agente NinjaOne en máquinas con Mac OS.

Entorno

Automatización NinjaOne

Descripción

Pegue el siguiente código en un archivo de texto y guárdelo con la extensión .sh , o descargue el script de shell adjunto a este artículo.

#!/bin/bash
## Iniciar Ninja Agent y la eliminación remota
if [[ $EUID -ne 0 ]]; then
    Write-LogEntry "Este script debe ejecutarse como root. Intente ejecutarlo con sudo o como usuario del sistema/root."
    exit 1
fi
LaunchDaemons=$(ls '/Library/LaunchDaemons' | grep 'ninjarmm')
if [[ -z ${LaunchDaemons// /} ]]; then
    Write-LogEntry 'No se han encontrado demonios de inicio'
else
    for Daemon in $LaunchDaemons; do
        Write-LogEntry "Eliminando $Daemon"
        if [[ $Daemon =~ 'ncstreamer' ]]; then
            Write-LogEntry 'Descargando el demonio Ninja Remote...'
            launchctl unload "$Daemon"
        fi
        rm -f "$Daemon"
    hecho
fi
LaunchAgents=$(ls '/Biblioteca/LaunchAgents' | grep 'ninjarmm')
si [[ -z ${LaunchAgents// /} ]]; entonces
    Write-LogEntry 'No se encontraron agentes de inicio'
si
    for Agent in $LaunchAgents; do
        Write-LogEntry "Removing $Agent"
        rm -f "$Agent"
    done
fi
NinjaDir=/Applications/NinjaRMMAgent
if [[ -d $NinjaDir ]]; then
    Write-LogEntry "Removing $NinjaDir"
    rm -rf $NinjaDir
fi
# Detener el último proceso Ninja para evitar que se reinicie
NinjaProcesses=($(pgrep ninjarmm))
if [[ ${#NinjaProcesses[@]} -gt 0 ]]; then
    for NP in "${NinjaProcesses[@]}"; do
        Write-LogEntry "Deteniendo el proceso NinjaRMM $NP"
        kill -9 "$NP"
    done
    CheckRemaining=$(pgrep ninjarmm)
    if [[ -z "$CheckRemaining" ]]; then
        Write-LogEntry "Todos los procesos NinjaRMM han sido detenidos correctamente."
    else
        Write-LogEntry "No se han podido detener todos los procesos NinjaRMM, ¡abortando!"
        Write-LogEntry "Procesos restantes: $CheckRemaining"
    fi
fi
# Limpieza de Ninja Remote
NinjaRemoteProcess=($(pgrep ncstreamer))
if [[ ${#NinjaRemoteProcess[@]} -gt 0 ]]; then
    for NRP in "${NinjaRemoteProcess[@]}"; do
        Write-LogEntry "Deteniendo el proceso Ninja Remote $NRP"
        kill -9 "$NRP"
    done
    CheckRemaining=$(pgrep ncstreamer)
    if [[ -z "$CheckRemaining" ]]; then
        Write-LogEntry "Se han detenido correctamente todos los procesos Ninja Remote."
    else
        Write-LogEntry "No se han podido detener todos los procesos Ninja Remote. Asegúrate de que no hay sesiones NR activas."
        Write-LogEntry "Procesos restantes: $CheckRemaining"
    fi
fi
SettingsPath='Biblioteca/Preferencias'
for UserPath in /Usuarios/*; do
    Usuario=$(basename "$UserPath")
    if [[ $Usuario != 'Compartido' ]]; then
        FullPath="/Usuarios/$Usuario/$SettingsPath"
        if [[ -d $FullPath ]]; then
            NRSettingsFiles=$(ls "$FullPath" | grep 'ninjarmm')
            if [[ ${NRSettingsFiles// /} ]]; then
                for NRFile in $NRSettingsFiles; do
                    Write-LogEntry "Removing $FullPath/$NRFile"
                    rm -f "$FullPath/$NRFile"
                done
            fi
        fi
    fi
done
NRPrinter='/Library/Impresoras/NinjaRemote'
if [[ -d "$NRPrinter" ]]; then
    Write-LogEntry "Removing Ninja Remote printer at $NRPrinter"
    rm -rf "$NRPrinter"
fi
NRPrinterBackend='/usr/libexec/cups/backend/nrprinter'
if [[ -f "$NRPrinterBackend" ]]; then
    Write-LogEntry "Eliminando impresora Ninja Remote en $NRPrinterBackend"
    rm -f "$NRPrinterBackend"
fi
if lpstat -p "NinjaRemote" /dev/null 2&1; then
    Write-LogEntry 'Eliminando impresora Ninja Remote desde CUPS'
    lpadmin -x NinjaRemote
fi
NRPShared='/Users/Shared/NrPdfPrint'
if [[ -f $NRPShared ]]; then
    Write-LogEntry 'Removing shared printer file'
    rm -f "$NRPShared"
fi
NRDir='/Applications/NinjaRemote'
if [[ -d $NRDir ]]; then
    Write-LogEntry 'Removing Ninja Remote directory'
    rm -rf "$NRDir"
fi

FAQ

Próximos pasos