What You'll Learn
- Using non-interactive mode
- PowerShell scripting examples (Windows)
- Bash scripting examples (Linux/Mac)
- Scheduled scans with Task Scheduler and cron
- Error handling and logging
- Monitoring and alerts
Overview
FileFortress supports non-interactive mode for automation. This allows you to create scripts that run FileFortress commands without user interaction, perfect for scheduled tasks, backup workflows, and monitoring.
Non-Interactive Mode
Add --non-interactive flag to any command to suppress prompts and confirmations:
filefortress remotes scan --all --non-interactive
PowerShell Scripting (Windows)
Basic Scan Script
simple-scan.ps1
# Simple scan script
$ErrorActionPreference = "Stop"
# Define key file location
$keyFile = "$env:USERPROFILE\filefortress.key"
try {
Write-Host "Starting FileFortress scan..." -ForegroundColor Green
filefortress --key-file $keyFile remotes scan --all --non-interactive
Write-Host "Scan completed successfully!" -ForegroundColor Green
}
catch {
Write-Host "Scan failed: $_" -ForegroundColor Red
exit 1
}
Advanced Scan Script with Logging
advanced-scan.ps1
# Advanced scan script with logging and error handling
$ErrorActionPreference = "Stop"
# Configuration
$keyFile = "$env:USERPROFILE\filefortress.key"
$logDir = "$env:USERPROFILE\FileFortress\logs"
$logFile = Join-Path $logDir "scan-$(Get-Date -Format 'yyyy-MM-dd').log"
# Ensure log directory exists
if (-not (Test-Path $logDir)) {
New-Item -ItemType Directory -Path $logDir | Out-Null
}
function Write-Log {
param($Message, $Level = "INFO")
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"[$timestamp] [$Level] $Message" | Tee-Object -FilePath $logFile -Append
}
try {
Write-Log "Starting FileFortress scan"
# Check for updates
Write-Log "Checking for updates..."
filefortress --key-file $keyFile update --non-interactive
# Scan all remotes
Write-Log "Scanning remotes..."
filefortress --key-file $keyFile remotes scan --all --non-interactive
Write-Log "Scan completed successfully" "SUCCESS"
}
catch {
Write-Log "Scan failed: $_" "ERROR"
exit 1
}
Bash Scripting (Linux/Mac)
Basic Scan Script
simple-scan.sh
#!/bin/bash
set -e
# Define key file location
KEY_FILE="$HOME/filefortress.key"
echo "Starting FileFortress scan..."
filefortress --key-file "$KEY_FILE" remotes scan --all --non-interactive
echo "Scan completed successfully!"
Advanced Script with Logging
advanced-scan.sh
#!/bin/bash
set -e
# Configuration
KEY_FILE="$HOME/filefortress.key"
LOG_DIR="$HOME/FileFortress/logs"
LOG_FILE="$LOG_DIR/scan-$(date +%Y-%m-%d).log"
# Ensure log directory exists
mkdir -p "$LOG_DIR"
log() {
local level="${2:-INFO}"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$level] $1" | tee -a "$LOG_FILE"
}
log "Starting FileFortress scan"
# Check for updates
log "Checking for updates..."
filefortress --key-file "$KEY_FILE" update --non-interactive || true
# Scan all remotes
log "Scanning remotes..."
if filefortress --key-file "$KEY_FILE" remotes scan --all --non-interactive; then
log "Scan completed successfully" "SUCCESS"
else
log "Scan failed" "ERROR"
exit 1
fi
Scheduled Tasks
Windows Task Scheduler
Create a scheduled task to run your PowerShell script daily:
# Create scheduled task (run as Administrator)
$action = New-ScheduledTaskAction -Execute "powershell.exe" `
-Argument "-ExecutionPolicy Bypass -File C:\Scripts\filefortress-scan.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At "3:00AM"
$principal = New-ScheduledTaskPrincipal -UserId "$env:USERNAME" -LogonType S4U
Register-ScheduledTask -TaskName "FileFortress Daily Scan" `
-Action $action -Trigger $trigger -Principal $principal
Linux/Mac Cron
Add to crontab to run daily at 3 AM:
# Edit crontab
crontab -e
# Add this line for daily scan at 3 AM
0 3 * * * /home/user/scripts/filefortress-scan.sh >> /var/log/filefortress-cron.log 2>&1
Pro Tip
Run scans during off-peak hours to minimize impact on your system and cloud API rate limits.
Related Articles
- Encryption Guide - Learn about key file setup
- Troubleshooting Guide - Debug common issues