cleanup demo script

This commit is contained in:
Jason Shirk 2016-07-21 09:56:14 -07:00
parent 444769cb6b
commit 3fb9315fce

View file

@ -1,21 +1,27 @@
Import-Module $PSScriptRoot/CronTab/CronTab.psd1
# Get the existing cron jobs
Get-CronJob
Write-Host -Foreground Yellow "Remove all jobs to start, no prompting"
Get-CronJob | Remove-CronJob -Force
# New cron job to clean out tmp every day at 1am
New-CronJob -Command 'rm -rf /tmp/*' -Hour 1
Write-Host -Foreground Yellow "Get the existing cron jobs"
Get-CronJob | Out-Host
# New cron job to start a build
New-CronJob -Command 'powershell -c "cd ~/src/PowerShell; ipmo ./build.psm1; Start-PSBuild"' -Hour 2 -DayOfWeek 1-5
Write-Host -Foreground Yellow "New cron job to clean out tmp every day at 1am"
New-CronJob -Command 'rm -rf /tmp/*' -Hour 1 | Out-Host
# Sort them by data
Get-CronJob | Sort-Object Command
Write-Host -Foreground Yellow "Add some more jobs"
New-CronJob -Command 'python -c ~/scripts/backup_users' -Hour 2 -DayOfWeek 1-5 | Out-Host
New-CronJob -Command 'powershell -c "cd ~/src/PowerShell; ipmo ./build.psm1; Start-PSBuild"' -Hour 2 -DayOfWeek * | Out-Host
# Show in bash that the new cron job exists
Write-Host -Foreground Yellow "Show in bash that the new cron job exists"
crontab -l
# Remove a cron job
Get-CronJob | Where-Object { $_.Command -match '^powershell.*' } | Remove-CronJob
Write-Host -Foreground Yellow "Get jobs that run every day"
Get-CronJob | Where-Object { $_.DayOfWeek -eq '*' -or $_.DayOfWeek -eq '1-7' } | Out-Host
Write-Host -Foreground Yellow "Remove one cron job, with prompting to confirm"
Get-CronJob | Where-Object { $_.Command -match '^powershell.*' } | Remove-CronJob | Out-Host
Write-Host -Foreground Yellow "And the other job remains"
Get-CronJob | Out-Host