Automation & Scripting

Automate FileFortress tasks with scripts and scheduled jobs

Advanced 45 minutes
1
Non-Interactive
2
Script
3
Schedule
4
Errors
5
Monitor

Step 1: Understanding Non-Interactive Mode

Essential for automated scripts

Use --non-interactive flag to suppress prompts:

filefortress remotes scan --all --non-interactive

Important

This is essential for automated scripts that run without user interaction.

Step 2: Create Your First Script

PowerShell and Bash examples

PowerShell (Windows)

# scan-daily.ps1

$keyFile = "$env:USERPROFILE\filefortress.key"

filefortress --key-file $keyFile remotes scan --all --non-interactive

Bash (Linux/Mac)

#!/bin/bash

# scan-daily.sh

KEY_FILE="$HOME/filefortress.key"

filefortress --key-file "$KEY_FILE" remotes scan --all --non-interactive

Step 3a: Schedule Task (Windows)

Using Task Scheduler

# Create scheduled task for daily scan at 2 AM

$action = New-ScheduledTaskAction -Execute "PowerShell.exe" `

  -Argument "-File C:\Scripts\scan-daily.ps1"

$trigger = New-ScheduledTaskTrigger -Daily -At 2am

Register-ScheduledTask -TaskName "FileFortress Daily Scan" `

  -Action $action -Trigger $trigger

Step 3b: Schedule Task (Linux/Mac)

Using cron

# Edit crontab

crontab -e


# Add daily scan at 2 AM

0 2 * * * /home/username/scripts/scan-daily.sh

Step 4: Error Handling and Logging

Add logging to track script execution

# PowerShell with logging

$logFile = "$env:USERPROFILE\FileFortress\logs\scan.log"

try {

  "[$(Get-Date)] Starting scan" | Out-File $logFile -Append

  filefortress --key-file $keyFile remotes scan --all --non-interactive

  "[$(Get-Date)] Scan completed" | Out-File $logFile -Append

} catch {

  "[$(Get-Date)] Error: $_" | Out-File $logFile -Append

}

Step 5: Monitoring and Alerts

Send notifications on success or failure

# PowerShell with email notification

if ($?) {

  Send-MailMessage -To "[email protected]" `

    -Subject "Scan Success" -Body "Scan completed"

} else {

  Send-MailMessage -To "[email protected]" `

    -Subject "Scan Failed" -Body "Check logs"

}

Automation Best Practices

  • Always use --non-interactive flag
  • Use key files instead of passwords
  • Implement comprehensive logging
  • Add error handling and notifications
  • Test scripts manually before scheduling
  • Schedule during off-peak hours

Learn More

Explore advanced automation patterns: