Skip to content
/ nas Public

(not so) simple bash (<4) script to control a linux based NAS (wake on lan, shutdown, mount volumes)

License

Notifications You must be signed in to change notification settings

crra/nas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

πŸ“š About

nas is a (not so) simple bash script for controlling your NAS (network attached storage). It allows the basic operations to wake and to shutdown the NAS. It also supports mounting a defined list of shares via the config file.

It's currently tested with a linux-based NAS from Synology on a macOS host (Big Sur).

It's developed for bash version <4 (e.g. shipped with Big Sur) and contains some quirks that are needed for such an old bash version (bash, version 3.2.57(1)-release is from 2007). It also works without changes on Monterey (12.1, 21C52).

πŸ’‘ Note from the author

Hopefully, from an educational perspective, the 'how' instead of the 'what' of this bash script is interesting for the curious reader. It uses several bash (version <4) techniques like e.g. string and list processing, regex, default value handling, config file, a small parser for the config file format, checking for commands, trimming, timeout handling, port checks with netcat, etc. Have fun reading the shellcheck'ed code.

Screenshot

screenshot of the interface Note: color added for clarity

Prerequisites

  • a machine running macOS (it's tested with Big Sur)
  • homebrew (https://brew.sh)
  • brew install wakeonlan
    I know the implementation uses perl, but the version of netcat shipped with macOS does not support the -b (for broadcast) option. 😒
  • SSH access and root access on your NAS
  • enabled wake-on-lan on your NAS
  • optional add your public ssh key to authorized_keys on your NAS

Installation (proposal)

  • create a $HOME/bin folder and add this folder to your $path environment variable
  • copy (or symlink ln -s) nas and the nas.env.example into the $HOME/bin folder
  • copy the nas.env.example file to $HOME/.config/nas/nas
  • edit the file $HOME/.config/nas/nas:
    • adjust the 'mandatory' variables to your needs
    • remove the 'optional' variables if the defaults work for you
    • For your reference, my config only contains:
      • config_hostname
      • config_mac
      • config_shares
  • macOS only: add the shares you want to mount after the host is up: config_shares="Share1, Share2"

Usage

$ nas up
wakes the NAS and mounts the configured shares

$ nas down
shuts down the NAS

Reading material

About

(not so) simple bash (<4) script to control a linux based NAS (wake on lan, shutdown, mount volumes)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages