Argomento
Questo script rimuove NinjaOne Agent dai computer Mac OS.
Ambiente
Automazione NinjaOne
Descrizione
Incolla il seguente codice in un file di testo e salvalo con estensione .sh , oppure scarica lo script shell allegato a questo articolo.
#!/bin/bash
## Avvia Ninja Agent e la rimozione remota
if [[ $EUID -ne 0 ]]; then
Write-LogEntry "Questo script deve essere eseguito come root. Prova a eseguirlo con sudo o come utente di sistema/root."
exit 1
fi
LaunchDaemons=$(ls '/Libreria/LaunchDaemons' | grep 'ninjarmm')
if [[ -z ${LaunchDaemons// /} ]]; then
Write-LogEntry 'No Launch Daemons found'
else
for Daemon in $LaunchDaemons; do
Write-LogEntry "Removing $Daemon"
if [[ $Daemon =~ 'ncstreamer' ]]; then
Write-LogEntry 'Unloading Ninja Remote daemon...'
launchctl unload "$Daemon"
fi
rm -f "$Daemon"
fatto
fi
LaunchAgents=$(ls '/Libreria/LaunchAgents' | grep 'ninjarmm')
se [[ -z ${LaunchAgents// /} ]]; allora
Write-LogEntry 'Nessun agente di avvio trovato'
altrimenti
per Agente in $LaunchAgents; fare
Write-LogEntry "Rimozione di $Agent"
rm -f "$Agent"
fatto
fi
NinjaDir=/Applicazioni/NinjaRMMAgent
se [[ -d $NinjaDir ]]; allora
Write-LogEntry "Rimozione di $NinjaDir"
rm -rf $NinjaDir
fi
# Termina l'ultimo processo Ninja per impedire che si riavvii
NinjaProcesses=($(pgrep ninjarmm))
if [[ ${#NinjaProcesses[@]} -gt 0 ]]; then
for NP in "${NinjaProcesses[@]}"; do
Write-LogEntry "Terminando il processo NinjaRMM $NP"
kill -9 "$NP"
done
CheckRemaining=$(pgrep ninjarmm)
if [[ -z "$CheckRemaining" ]]; then
Write-LogEntry "Tutti i processi NinjaRMM sono stati terminati con successo."
else
Write-LogEntry "Impossibile terminare tutti i processi NinjaRMM, interruzione in corso!"
Write-LogEntry "Processi rimanenti: $CheckRemaining"
fi
fi
# Pulizia Ninja Remote
NinjaRemoteProcess=($(pgrep ncstreamer))
if [[ ${#NinjaRemoteProcess[@]} -gt 0 ]]; then
for NRP in "${NinjaRemoteProcess[@]}"; do
Write-LogEntry "Terminazione processo Ninja Remote $NRP"
kill -9 "$NRP"
done
CheckRemaining=$(pgrep ncstreamer)
if [[ -z "$CheckRemaining" ]]; then
Write-LogEntry "Tutti i processi Ninja Remote sono stati terminati con successo."
else
Write-LogEntry "Impossibile terminare tutti i processi Ninja Remote. Assicurati che non ci siano sessioni NR attive."
Write-LogEntry "Processi rimanenti: $CheckRemaining"
fi
fi
SettingsPath='Libreria/Preferenze'
for UserPath in /Users/*; do
User=$(basename "$UserPath")
if [[ $User != 'Condiviso' ]]; then
FullPath="/Users/$User/$SettingsPath"
if [[ -d $FullPath ]]; then
NRSettingsFiles=$(ls "$FullPath" | grep 'ninjarmm')
if [[ ${NRSettingsFiles// /} ]]; then
for NRFile in $NRSettingsFiles; do
Write-LogEntry "Rimuovendo $FullPath/$NRFile"
rm -f "$FullPath/$NRFile"
done
fi
fi
fi
fatto
NRPrinter='/Library/Stampanti/NinjaRemote'
if [[ -d "$NRPrinter" ]]; then
Write-LogEntry "Rimozione stampante Ninja Remote su $NRPrinter"
rm -rf "$NRPrinter"
fi
NRPrinterBackend='/usr/libexec/cups/backend/nrprinter'
if [[ -f "$NRPrinterBackend" ]]; then
Write-LogEntry "Rimozione stampante Ninja Remote su $NRPrinterBackend"
rm -f "$NRPrinterBackend"
fi
if lpstat -p "NinjaRemote" /dev/null 2&1; then
Write-LogEntry 'Rimozione stampante Ninja Remote da CUPS'
lpadmin -x NinjaRemote
fi
NRPShared='/Users/Shared/NrPdfPrint'
if [[ -f $NRPShared ]]; then
Write-LogEntry 'Rimozione file stampante condivisa'
rm -f "$NRPShared"
fi
NRDir='/Applications/NinjaRemote'
if [[ -d $NRDir ]]; then
Write-LogEntry 'Rimozione directory Ninja Remote'
rm -rf "$NRDir"
fi