Git Product home page Git Product logo

unix_like_scripts's Introduction

How to run

  1. clone this project somewhere
  2. cd to this project directory, linux-scripting
  3. run command source xxx

Bash

Bash Beginners Guide

Coding Convention

  • Sha-bang aka. Shebang

The sha-bang (#!) at the head of a script tells your system that this file is a set of commands to be fed to the command interpreter indicated.

This is a Linux-based Bash script project, i.e. non-POSIX. So sha-bang #!/bin/bash is used.

Reference: Advanced Bash-Scripting Guide > Chapter 2. Starting Off With a Sha-Bang

  • Variables

When referencing a variable, surround its name with curly braces to clarify to the parser and to human readers where the variable name stops and other text begins; for example, ${etcdir} instead of just $etcdir

There's no standard convention for the naming of shell variables, but all-caps names typically suggest environment variables or variables read from global configuration files. More often than not, local variable are all-lowercase with components separated by underscores.

Reference: UNIX AND LINUX SYSTEM ADMINISTRATION HANDBOOK (4th edition) > Chapter 2 Scripting and the Shell > Shell basics > Variables and quoting (P/33)

  • Functions

Declaring a function is just a matter of writing function my_func { my_code }. Calling a function is just like calling another program, just write its name.

Reference: BASH Programming - Introduction HOW-TO > 8. Functions

  • Coding Strategy

Try to replace old style auxiliary language like sed, awk with python in case the syntax is too complicated to be readable.

Code Description

configure_debian_functions.sh

How to use functions in configure_debian_functions.sh

All the functions are about installing extra software, usually to /opt. In order to install software to /opt,

  1. go to the directory of this script, shift to sudo mode with su command
  2. give the password of sudo, click enter to shift to sudo mode
  3. source configure_debian_function.sh
  4. call any of the functions in configure_debian_functions.sh, e.g. install_maven

bash configure_my_debian.sh

TODO

  • Add a crontab to shutdown PC at a specified time every day
  • Command instead of logout for Xsession refresh still unsolved, source /etc/X11/Xsession encountered errors
  • In case of installing on Virtual Box, add the Guest Addition installation script
  • Install the lvm2 (Logical Volume Manager) and make use of it to manage the disk instead of partitions (As administrators get comfortable with logical volume management, partitions are disappearing, too.). Try to make use of snapshots to make a backup mechanism with an external storage device
  • Make an lost+found mechanism like the recycle bin in Windows
  • 20170206: based on the Java class file format (refer to https://en.wikipedia.org/wiki/Java_class_file and http://stackoverflow.com/questions/698129/how-can-i-find-the-target-java-version-for-a-compiled-class), create a script to get the Java class version information

Reference: UNIX AND LINUX SYSTEM ADMINISTRATION HANDBOOK (4th edition) > Chapter 8 Storage > 8.4 Peeling the Onion: The Software Side of Storage (P/222)

mounted_disk_monitor.sh

Technical keywords:

  • getopts
  • rsyslog > command logger with option -t
  • process substitution

TODO

  • WARNING SHOULD BE SENT ONCE A DAY, whereas currently it is sent only ONCE

Learning

FAQ


  • How to check the distribution version of your current Linux Answer: Distribution version is stored in /etc/os-release
  • How to get running script directory: $(cd `dirname $0` && pwd)
  • How to list the system's disks and identify the new drive: sudo fdisk -l
  • How search text from a File with less from bottom up: ?keyword

Other Software Installation

https://github.com/nodesource/distributions#debmanual

unix_like_scripts's People

Contributors

rxue avatar

Watchers

James Cloos avatar  avatar

unix_like_scripts's Issues

Error when opening file with vim

Error detected while processing /etc/vim/vimrc.local:
line    1:
E488: Trailing characters: # Reference: http://tldp.org/LDP/abs/html/here-docs.html
line    2:
E488: Trailing characters: # Configure VIM on the system level
line    9:
E518: Unknown option: # 
Press ENTER or type command to continue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.