Meeting-2018-08-25-Bash Scripting

So, it turns out that WordPress doesn’t like my little script, and if you want a copy of it, you’ll need to download it with;


Some days I just don’t appreciate a CMS as much as I should…

#!/bin/bash -i
# This script shows some of the features of the Bourne Again SHell
# or bash.
# It is designed to be run from a terminal as a presentation,
# Steve Jones, for the 2008-04-26 meeting,
# Updates and information will be made available as quickly
# as time permits.
# Edited and presented again for the 2018-08-25 meeting.
# Test to see if we were given a starting slide on
# the command line
if [ "$1x" = "x" ] 	# The special variable $1 is the first
then Slide=1	# argument on the command line, $2 is
else		# the second, etc... Here we check to
Slide=$1	# see if a slide number was given.

# Wait for a keypress and then continue on with the script.
Wait() {
# This is a function, it is delimited by the curly brackets
# above and below. It stops at the current cursor location
# and silently waits for a keypress
read -s -n 1 Anykey

# Format stdin to fit nicely on the screen.
Format() {
# Another function, this one is handed input on stdin, it then
# breaks it into nice, screen width-or-less lines.
fmt --split-only --width=$COLUMNS

# Pause for a second
Sleep() {
read -s -n 1 -t 1 Anykey

# Wait for a keypress at the bottom of the screen then clear
# the screen before continuing on with the script.
Pause() {
echo -en "\033[$LINES;5H"
# Read (-s, Silently) (-n 1, Single Char) (-p, "Prompt") Variable
read -s -n 1 -p "$Slide " Anykey

# Set the screen for black text on a grey background.
CodeOn() {
echo -e "\033[47m\033[30m"

# Set the screen back to black on white.
CodeOff() {
echo -e "\033[0m"

# Put a title on each page and center it on the top line
Title() {
EightySpaces="                                                                                "
Spaces="${EightySpaces:0:$(( ($COLUMNS/2)-$(( ${#1}/2 )) ))}"
echo "$Spaces"$1
# Okay, this needs an explanation. The EightySpaces variable is
# just what it says, eighty space characters. The next line
# assigns a substring of $EightySpaces, starting at the first
# character (0, or leftmost), and continuing for half of the
# screen width minus half of the length of the title. The
# title is handed to the function at the time of invocation.

S-01() {
Title "What is Bash?"
# Our first slide, it is a function that contains a number of
# functions. First is the one above, which calls the title
# function to make things pretty, then the format function below
# to make the rest prettier.

Meeting-2016-06-25 The Picnic!

When: Saturday, June 25th. 10:30 – Dark
Where: H.F. Walsh Shelter, Rentschler Forest (Follow Signs)
Who: Members (and family) are invited, others may join at the picnic!!!

Now, the important issues, what do we want to eat? Use the form below to let us know!
[easy_contact_forms fid=7]

* Bring something to share: Beverages, Side dishes, Desserts!
* We’ll provide meat, flatware, napkins, cups, etc.
* Also, bring outdoor games, group games, maybe water balloons, anything!
* Electricity is NOT available at the site.
* A Motor Vehicle Permit is not required (it’s included with the shelter)
* Membership rates are prorated for new members.

Information about the park;

Address of the preserve: 5701 Reigart Rd, Hamilton, OH 45011

The preserve is North of Hamilton, very near the intersection of Route 4
and the
Route 4 Bypass.

Map of the park; BC-MetroParks
Directions to the park; Google
Information about the park; Rentschler Preserve

A thousand apologies about the late notice, a car ran into a pole near my
house and took out my Internet – I’m recovering slowly, I don’t know about
the driver.

Backing up MySQL Databases

This is the script I run every morning to back up all of the databases in my MySQL database – it gets every database, including mysql, which has the users and access rights for users.

Obviously, you’ll need to modify a few of the variables in the script, but it shouldn’t be difficult. There are a few comments in the script. Feel free to ask questions if you have them, you can always e-mail me with steve at clug dot org.

# MySQL backup script
# With a few modifications by Steve Jones
### System Setup ###
### MySQL Setup ###
MUSER="root"  ;  MPASS="Secret!"  ;  MHOST="localhost"
MYSQL=$(which mysql)
MYSQLDUMP=$(which mysqldump)
GZIP=$(which gzip)
NEW=$(date +%Y-%m-%d)
OLD=$(date -d "7 days ago" +%Y-%m-%d)
### Start Backup for file system ###
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :
### Start MySQL Backup ###
# Get all databases name
ALL=$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')
for DB in $ALL
  ### The perf_schema DB doesn't have events, it isn't even real.
  if [ "$DB" = "performance_schema" ]; then
    OPTS="--single-transaction --add-drop-table"
    OPTS="--single-transaction --events --add-drop-table"
  | $GZIP -9 > $NEWFILE
  ### If an oldfile exists, remove it. An added feature of this is that
  ### if you drop a DB, the last few days of its life will be here forever
  [ -f $OLDFILE ] && rm -f $OLDFILE

Meeting-2015-12-19 SSH, offering assistance in a hostile world

If you offer remote assistance to an unknown party, there are security implications that might not be obvious.
For you to connect to them, they need to have properly configured quite a lot of stuff, which is the issue.

This presentation will go over the security issues, ssh configuration issues, ssh usage, and more!

I’ll update this post with the full presentation next Sunday morning (Dec 20th), for the live presentation, come to the meeting.

Hope to see you there!


Meeting-2015-07-25 Update / Upgrade … Improvement in both … Dave Hemmerle

Update / Upgrade … Improvement in both … Method and Content. Dave Hemmerle / CLUG Handout
Traditional or Basic Update:

1. GUI : Through the “Update Manager” a GUI found by Applications > Systems Tools > Administration > Update Manager.

2. Command Line: Open the terminal or terminal emulator:
Type in a “sudo apt-get update -y && sudo apt-get upgrade -y”.
Followed by your password.
And finally the Update / Upgrade begins to run.

Improved automated method included:

1. A bash scrip, 2. a bin directory added to my home directory for the bash scrip, 3. password negated from sudo to run Update commands, and 4. Shortcut keys to run the Updare file showing the terminal as the file is ran so you know it ran.

Here are the steps to accomplish this:

1. The bash scrip and 2. a bin directory:
1. Create a “bin” directory in your ~/home/user_name/ directory.
2. Open a text editor an make the following bash scrip: “” file.

dave@dave-ThinkPad-T500:~/bin$ cat Update

# LOCATED: ~/home/dave/bin
# The following are the commands that I want to run to Update and Upgrade
# my applications as well as clean out some of the junk.
# This bash scrip or file( in ~/home/dave/bin/ and can be ran from the terminal
# or from, "Hot Keys" using " Alt + u".
# Although running a file that list files or having the ability to change files,
# requires "sudo" or "root" level permission the requirement for a "password" has
# been negated through the augmentation file "dave" .
# This file has been added to the /etc/sudoers.d/dave, and is read after the "sudoer" file.

# The last items read are used to establish the state of the password requirement.
# Thus,this augmenting file has the “last word” in the permission settings.
# And this indicate:
# NOPASSWD for user dave from ALL terminals, as ALL dave log on users, for the
# listed commands that follows:

sudo /usr/bin/apt-get -y update
sudo /usr/bin/apt-get -y upgrade
sudo /usr/bin/apt-get -y autoclean
sudo /usr/bin/apt-get -y autoremove


3. And make it into an executable ( “ chmod +x Update”), and then stored in your ~/home/user_name/bin/ .

This can be confirmed by “ls -lF Update” from the bin directory:

dave@dave-ThinkPad-T500:~$ cd bin && ls -lF
total 12
-rwxrwxr-x 1 dave dave 37 May 3 07:00*
-rwxrwxr-x 1 dave dave 231 May 1 18:58*
-rwxrwxr-x 1 dave dave 150 Jun 25 14:58 Update*

Note the file Update* has an asterisk , as well as -rwxrwx-x in ownership, both of which indicate an executable file. Since update and upgrade can make changes above your normal user permission level, you need to use “sudo” elevate your permission level to that of a superuser, or root, and it takes a password to authenticate yourself, unless the password requirement has been negated.

3. No Password for the commands:

Now there is another change that is needed. The ability to run the apt-get commands without stopping to input your password. This is accomplished through “sudoers”, and a file in the “sudoers.d” directory
that has files read, after “sudoers” that amends “sudoers” default permissions. ( .d files / augmentation )

Make a file “your user name” in /root/etc/sudoers.d directory. Keep in mind that this file is above your normal user home and other users may need to add similar files. Putting them in the user’s name will keep it easier to maintain.

Change directory to your “root /etc “directory and then … from the root/ … ls | grep “sudo” , ( there are a lot of files in “etc” and and we are only interested in the ones with sudo in their names ), here is what I get:

dave@dave-ThinkPad-T500:/$ cd etc
dave@dave-ThinkPad-T500:/etc$ ls | grep “sudo”

1. If you do not have a “sudoers.backup ”, backup the “sudoers”.

2. Then sudo cat sudoers:

dave@dave-ThinkPad-T500:/etc$ sudo cat sudoers
[sudo] password for dave:
# This file MUST be edited with the ‘visudo’ command as root.
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
# See the man page for details on how to write a sudoers file.
Defaults env_reset
Defaults secure_path=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command

# See sudoers(5) for more information on “#include” directives:

#includedir /etc/sudoers.d

3. “sudoers.d” is a directory … change into itand list its contenance … then “sudo cat README”.

This is what it says:

dave@dave-ThinkPad-T500:/etc/sudoers.d$ sudo cat README
# As of Debian version 1.7.2p1-1, the default /etc/sudoers file created on
# installation of the package now includes the directive:
# #includedir /etc/sudoers.d
# This will cause sudo to read and parse any files in the /etc/sudoers.d
# directory that do not end in ‘~’ or contain a ‘.’ character.
# Note that there must be at least one file in the sudoers.d directory (this
# one will do), and all files in this directory should be mode 0440.
# Note also, that because sudoers contents can vary widely, no attempt is
# made to add this directive to existing sudoers files on upgrade. Feel free
# to add the above directive to the end of your /etc/sudoers file to enable
# this functionality for existing installations if you wish!

I used my text editor and made the file “dave” that has additional user privilege specification:

dave@dave-ThinkPad-T500:/etc/sudoers.d$ sudo cat dave

# This file is in the sudoers.d directory and will be read
# after the sudoers file. Thus these permissions will be
# the last read and thus will be used.

# The statements indicate that when dave is the log in person …
# he can use ALL (terminals) … =(ALL) (as all users) … with
# NOPASSWD … needed for the following commands in the
# /usr/bin/apt-get -y update ….

dave ALL=(ALL) NOPASSWD: /usr/bin/apt-get -y update
dave ALL=(ALL) NOPASSWD: /usr/bin/apt-get -y upgrade
dave ALL=(ALL) NOPASSWD: /usr/bin/apt-get -y autoclean
dave ALL=(ALL) NOPASSWD: /usr/bin/apt-get -y autoremove

( user name (ALL=(ALL) ALL = MUC,
M=Machine or terminal, U=Users (or any other user name this user name may be using, and C=Commands, what Commands are involved. )

The file dave is not an “executable” file as there is no scrip to be run. However this file need read permission (0440), so “sudoers” can be read and thus be used to change/augment the sudo password requirement.

We now have a “executable” bash scrip file called “Upgrade” in my users /home/user_name/bin/ directory. The sudo permission does not require a password when the log in person is dave
and the apt-get commands have had their permission changed to NOPASSWD , the -y option ( is so there is no stopping for input when the commands are ran.

To check for special sudo permissions type “sudo -l”
I now show:

dave@dave-ThinkPad-T500:~$ sudo -l
Matching Defaults entries for dave on this host:

User dave may run the following commands on this host:
(ALL) NOPASSWD: /usr/bin/apt-get -y update
(ALL) NOPASSWD: /usr/bin/apt-get -y upgrade
(ALL) NOPASSWD: /usr/bin/apt-get -y autoclean
(ALL) NOPASSWD: /usr/bin/apt-get -y autoremove

4. Shortcut Keys:

All we need now is to have the “Update” file explicable from “Shortcut keys”.

Go to “Systems Settings”, Applications > Systems Tools > Systems Settings

When Systems Settings opens up go to the Hardware grouping and open the Keyboard …
in the Keyboard window select the Shortcut tab. Near the bottom of this window there is a narrow strip with a + and – sign. Click on the + and a window will open up so you can add a custom shortcut key.

In the Name window put “Update”. ( This is not the file but just any name to identify this command.)
In the Command window input the command to be run. At first I used “/home/dave/bin/Update”.

Clicked Apply and the new shortcut command name will appear, however, it will be listed as
“Disabled” where the hot keys should be noted.

Click on the term “Disabled” and input the hot key the keys you want to use to run this command. I used “Alt + u”. Close the shortcut window and try the shortcut key.

All seemed to run ok no error messages ??? , however, there was no observed sign that it was working, so the command in the “Shortcut key” was improved / changed to:
“gnome-terminal -e /home/dave/bin/Update”

When this command is ran, the gnome-terminal is displayed for a brief time and the scrip can be seen running.

“Wa La” … Press Alt + u, and the applications that were downloaded through the PPA’s are updated / upgraded, and purged of obsolete junk.

Meeting-2015-06-27 The Picnic!

This meeting is open to members only!

If you are not currently a member (nobody is, see previous post), then pro-rated dues are expected. Those dues are;

  • $12.50 for a Family Membership
  • $10.00 for an Individual Membership
  • $5.00 for a Student Membership

The June meeting of the Cincinnati Linux Users Group will be our annual picnic, held at the GE Condo shelter in Rentschler Park, Butler County, Ohio.

For a Google map to the park, click here. This should open in a new tab or window.

For a .pdf file of the park, click here. This should open in a new tab or window.

The group provides the meat and cooking, Members are requested to bring drinks and side dishes.

This post will be updated as the event draws near!


The meeting today concerned the format of future meetings. Over the years the group has moved away from the formal style we started with to a far more casual and unstructured format. Dues have not been collected for years, introductions are rarely made, topics have been spotty at best.

I take responsibility for these issues and others, and am trying to rectify them now.
The CLUG Bylaws have been posted, please read them and be aware that in the future, they will be used to govern the direction and intent of the group.

Technically, there were no members in attendance as we have no dues paying members. The following folks showed up to discuss where the group is headed;

  • Bill Stowell
  • Parker Jones
  • Mike Bechtold
  • Dave Hemmerle
  • Mike Lau
  • Anthony Strauss
  • Edwin Clements
  • Jonathan Jacobs
  • Lance Feldmen
  • Mike Humerickhouse
  • Sandi Jones
  • Duncan Jones
  • Brett Birdsall
  • Steve Jones

Offices were discussed and volunteers stepped forward to fill the positions of;

  • President: Steve Jones
  • Vice President: Dave Hemmerle
  • Secretary: Bill Stowell
  • Treasurer: Mike Bechtold
  • Program Director: Mike Lau
  • Program Director: Anthony Strauss
  • Program Director: Jonathan Jacobs

The treasury currently holds approximately $1225.00, after debiting $75.00 for a picnic shelter for the June meeting.

The group was called to order at 10:35, and was released to disorder at 12:00.