Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome, Safari or Firefox browser.

CIS 225

Lecture 8: Scripting and Automation 2

Review

Select Statement

#!/bin/bash
#simplemenu.sh
OPTIONS="Build Run Clean Quit"
select opt in $OPTIONS; do
  if [ "$opt" = "Build" ]; then
    echo "Building project..."
  elif [ "$opt" = "Run" ]; then
    echo "Running project..."
  elif [ "$opt" = "Clean" ]; then
    echo "Cleaning project..."
  elif [ "$opt" = "Quit" ]; then
    echo "Exiting..."
    break
  else
    echo "Invalid Input"
  fi
done
exit 0

Select Statement

User Input

#!/bin/bash
#simpleinput.sh
echo "Input your name and press [ENTER]"
read name
echo "Welcome $name!"
exit 0

User Input

Scheduling Tasks - Cron

Cron allows you to schedule tasks to run a specific times
Very useful for tasks that need done regularly

Cron HowTo

$ crontab -e

Edit the current cron schedule

$ crontab -l

View the current cron schedule

$ sudo crontab -e

Edit the root cron schedule

Crontab

Crontab Timing

PowerShell Menu

$title = "Select Options"
$message = "Choose an option to perform"
$build = New-Object `
  System.Management.Automation.Host.ChoiceDescription `
  "&Build", "Build the project"
$run = New-Object `
  System.Management.Automation.Host.ChoiceDescription `
  "&Run", "Run the project"
$clean = New-Object `
  System.Management.Automation.Host.ChoiceDescription `
  "&Clean", "Clean the project"
$quit = New-Object `
  System.Management.Automation.Host.ChoiceDescription `
  "&Quit", "Quit"
$options = `
  [System.Management.Automation.Host.ChoiceDescription[]] `
  ($build, $run, $clean, $quit)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
switch ($result)
{
    0 {"You selected Build"}
    1 {"You selected Run"}
    2 {"You selected Clean"}
    3 {"You selected Quit"}
}

PowerShell Menu

PowerShell Input

$name = Read-Host `
    "Input your name and press [ENTER]"
Write-Host "Welcome $name!"

PowerShell Input

Windows Task Scheduler

Windows Create Task

Windows Create Task

Windows Create Task

Reading

Assignments