Raspberry PI – excuting shell scripts

How to execute a shell script on your Raspberry PI?

  • create a diretory for the script, for instance:
    sudo mkdir /home/pi/Code
  • create a shell script with nano (or another editor):
    sudo nano /home/pi/Code/updatePI.sh
  • example: the following shell script will update your RasPI:
    #!/bin/bash
    date
    echo UPDATING SYSTEM SOFTWARE – UPDATE
    sudo apt-get update
    echo UPDATING SYSTEM SOFTWARE – UPGRADE
    sudo apt-get upgrade
    echo UPDATING SYSTEM SOFTWARE – DISTRIBUTION
    sudo apt-get dist-upgrade
    echo REMOVING APPLICATION ORPHANS
    sudo apt-get autoremove –purge
    echo UPDATING FIRMWARE
    sudo rpi-update
  • make your script executable:
    sudo chmod +x /home/pi/Code/updatePI.sh
  • execute your script:
    sudo /home/pi/Code/updatePI.sh
  • if you are in the directory where the script is located use:
    sudo ./updatePI.sh

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.