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;

wget https://www.clug.org/Bashy

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, CLUG.org
# 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.
fi

# 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() {
clear
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.

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.

#!/bin/sh
# MySQL backup script
# With a few modifications by Steve Jones
### System Setup ###
BACKUP=$HOME/.MySQL-Backup
### 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
  do
  ### The perf_schema DB doesn't have events, it isn't even real.
  if [ "$DB" = "performance_schema" ]; then
    OPTS="--single-transaction --add-drop-table"
    else
    OPTS="--single-transaction --events --add-drop-table"
  fi
  NEWFILE=$BACKUP/$NEW-$DB.sql.gz
  OLDFILE=$BACKUP/$OLD-$DB.sql.gz
  $MYSQLDUMP $OPTS -u $MUSER -h $MHOST -p$MPASS $DB \
  | $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
done

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!

Steve

Meeting-2014-11-22

This meeting covered an installation of ownCloud, ending with an exciting software RAID rebuild done live!

The linked .pdf file is a complete walkthrough of the build.

Thank you to all who attended!

ownCloud

How to run a sub-domain of CLUG.Org

Why?

Because DNS is a great enabler!

Let’s say you want to share some information with the world but you have a regular, dynamic xDSL Internet connection. You start up a web server, open port 80 on your router, find your IP address is 72.49.120.103, then call some friends to let them know that address. All is amazing and wonderful. Every so often though, your IP address will change, and then you become lost to the world. You need to find out what your IP address is, then call those you want to share with and tell them your new address, it’s tedious and you have to wait for them to find a pen.

Enter Dynamic DNS!

Dynamic DNS allows you to associate a host name with an IP address which changes, such as one assigned to a dial-up intenet connection or a cable modem.

Instead of 72.49.120.103, you can be amy.clug.org! Even I can remember that.

How?

Step zero is to send an e-mail to president@clug.org, requesting a sub-domain, and it must include a phone number, I will not set up someone until I’ve talked to them! You can call me if you want, I have a Cincinnati number, Six Zero Four-5916.

Step one is to set up a service on your server, it can be SSH, HTTP, FTP, FreeCiv or anything else you like, but not Telnet, telnet is bad. A note on security, if you aren’t sure of the security implications of the software you want to run, at a minimum, do a Google search like “Linux howto secure ipp” beforehand, and no, there isn’t a space between how and to. Figure out what port or ports your service runs on, you can look in /etc/services or the man page, or use sudo nmap -sS 192.168.1.2 (where that last part is the LAN address of your server). Make sure that you can get to that service from another machine on your local network and that it gives back sane responses.

sudo nmap -sS 192.168.1.2

Starting Nmap 5.21 ( http://nmap.org ) at 2013-10-27 11:03 EDT
Nmap scan report for 192.168.1.2
Host is up (0.0000090s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
631/tcp open ipp
2222/tcp open unknown

Nmap done: 1 IP address (1 host up) scanned in 0.25 seconds

Step two is to set up your router, this is pretty much beyond the scope of this little howto, as there are a zillion different routers out there, and some of them can be a pain to set up in what the original builders think might be insecure (Apple Airport, I’m looking at you!). What you want to do is find an entry like “Port Forwarding” or “Game Access” in some cases, this is done by connecting to the built-in web-server that runs on the router itself, usually at http://192.168.1.1/ and looking through the menus you find there, after you change the password to something secure resembling ho3r0cqh@m – and no, that isn’t my password. In my case, I wanted to open access to SSH on the non-default port of 2222, so I forward port 2222 through 2222 to 192.168.1.2, port 2222. The port xx through yy is for a contiguous range of ports, the destination port is the lowest port in the range. Not all routers do this kind of range, but it is the most confusing of the ones I’ve found.

Step three is to figure out what your external IP address is. The script at the end of this article reads the address from my gateway router, however there are plenty of places on the Internet that can give you this information, for instance;

links -dump http://www.ipchicken.com/ | grep -oP "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"

and

links -dump http://www.cmyip.com/ | grep -oP "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"

In both of these, I’m using links, but you can use elinks, w3m, wget, lynx or anything else that returns a page on the command line. The pipe to grep takes the output before and returns only (o) the match for the perl (P) expression that matches an IPv4 address (Okay, it doesn’t, but it’s good enough).

My opinion is that reading the router is the better idea as it’s on the end of a very fast wire that doesn’t slow down my surfing speed.

Step four is to request a dynamic update of your hostname from http://freedns.afraid.org/dynamic/update.php with an argument of the SecretString that I provide you with. Each sub-domain has a unique SecretString, so these can be distributed easily, and used on a router if it runs dd-wrt or Tomato. As soon as you run;

SecretString="BgyVtp45gfnMrrd0n3D5GHns4b79saAKpTMAtv=="
wget -q --read-timeout=0.0 --waitretry=5 --tries=400 -O- \
http://freedns.afraid.org/dynamic/update.php?${SecretString}

your sub-domain should be active, a ping sent to clug.org should give my address, one sent to you.clug.org should give your ip address (They may or not succeed, but the addresses should be correct. Also, it doesn’t need to be run from your server, any machine that uses the same gateway router will work, though I can’t come up with a good reason to do this. One of the interesting things about this method is that it doesn’t need to be run as root, any user can run the script below.

You could just run the wget line above as a cron job, but please don’t, it puts an excessive load on the machines at Afraid.org and that irritates Joshua Anderson, the owner of Afraid.org.

Step five is to set up a cron job to do this work while you sleep,

crontab -l
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0-7) (Sun=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
*/10 * * * * ~/bin/Afraid.org.update.sh

The script looks up your external address, compares it to whatever it had been, and if it changes, requests an update. Save the script below as ~/bin/Afraid.org.update.sh and change the SecretString variable in line nine, replace the value shown with the one I give you. Don’t forget to make it executable!

#!/bin/sh
# Run me to set the external address up
#
# This script only tries to update if there is a change in our IP address
# or we loose the connection to the World Wide Web.

Logfile=${HOME}/.Afraid.org.log

SecretString="BgyVtp45gfnMrrd0n3D5GHns4b79saAKpTMAtv=="

# The lines below gets our IP address from the crappy little CBT Wireless
# router at home.
# They need to be modified if that router changes, or we use another service.
Current=`
links -source http://192.168.1.1/htmlV_Generic/home_Connect.asp \
| grep WanIPRoutingState_WanIPAddress \
| grep -oP "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
`

# Present the date in an easily grepable fashion.
Date=`
date +"%Y-%m-%d+%H:%M"
`

# If the Logfile doesn't exist, create it with a known IP address.
if [ ! -f $Logfile ] ; then
echo "$Date 0.0.0.0" >> $Logfile
fi

# If the Logfile still does not exist, something is wrong, cry for help.
if [ ! -f $Logfile ] ; then
echo "Cannot create $Logfile - check directory permissions"
exit 1
fi

Last=`
cat $Logfile | tail -1 | cut -d " " -f 2
`

if [ "$Current" = "$Last" ] ; then # No update is required, silently exit.
exit 0
fi

echo "Update of external IP address needed."
echo "$Date $Current" >> $Logfile
# The line below is from afraid.org and is what actually sets the DNS entries
# for the domain.
wget -q --read-timeout=0.0 --waitretry=5 --tries=400 -O- \
http://freedns.afraid.org/dynamic/update.php?${SecretString}

Step six, why didn’t it work?

It probably did work, you just can’t see the forest through the trees. Say you are on a machine with IP of 192.168.1.100, and your server is at 192.168.1.2, with the router at 192.168.1.1, your external address is 40.30.20.10, and port 80 is forwarded to the server.

When I try to connect from my machine at my house, everything works properly, DNS resolves your external address and I see the web page on your machine because your router forwards my request to your server.

When you try to connect, you resolve your external address, send the request out your router, which doesn’t understand why an internal address is trying to connect to another internal address through the router, so it drops the packet.

Before you spend hours trying to figure out what is going on, call somebody and ask if they can see your page, if they can, you’re golden.

To fix things so they work properly inside as well, add your server to your /etc/hosts file ( %SystemRoot%\system32\drivers\etc\hosts on Windows, /lib/ndb/hosts on Plan 9), and everything is good, unless you are on a laptop. If you are using a laptop and take the laptop to a friends house, when you try to connect, you resolve 192.168.1.2 which won’t work. It wouldn’t be difficult to write a script that looks at the name of your access point and modifies the hosts file if you are home, but your access point would need a unique name.

The proper way to fix this is to run your own internal DNS server, either on your router or on your server. The advantage of the router is that it’s pretty simple and you don’t need to worry about it once everything is set up, the advantage of the server is that you can do more with it, but you need to do more with it.

If you run dd-wrt, you can fix this by enabling dnsmasq, then adding your hostname to the Additional DNSMasq Options

expand-hosts
address=/www/192.168.1.2
address=/mail/192.168.1.2
address=/amy.clug.org/192.168.1.2

Free DNS from Afraid.Org

Raspberry Spi


# Insert an SD card into a Linux PC and;
sudo fdisk -l
#
# Disk /dev/sdb: 3965 MB, 3965190144 bytes
# 49 heads, 48 sectors/track, 3292 cylinders, total 7744512 sectors
# Units = sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 512 bytes
# I/O size (minimum/optimal): 512 bytes / 512 bytes
# Disk identifier: 0x00000000
#
# Device Boot Start End Blocks Id System
# /dev/sdb1 8192 7744511 3868160 b W95 FAT32

sudo umount /dev/sdb1

sudo dd if=archlinux-hf-2013-07-22.img of=/dev/sdb
# 1870+0 records in
# 1870+0 records out
# 1960837120 bytes (2.0 GB) copied, 203.495 s, 9.6 MB/s

sudo fdisk -l
#
# Disk /dev/sdb: 3965 MB, 3965190144 bytes
# 64 heads, 32 sectors/track, 3781 cylinders, total 7744512 sectors
# Units = sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 512 bytes
# I/O size (minimum/optimal): 512 bytes / 512 bytes
# Disk identifier: 0x00057540
#
# Device Boot Start End Blocks Id System
# /dev/sdb1 2048 186367 92160 c W95 FAT32 (LBA)
# /dev/sdb2 186368 3667967 1740800 5 Extended
# /dev/sdb5 188416 3667967 1739776 83 Linux

sudo gparted /dev/sdb
# Expand the sdb2 and sdb5 filesystems to use the whole SD card.

# Move the SD card to the 'pi and connect to a router that has internet access
# and another computer with ssh. The original passwd is 'root'

ssh root@192.168.2.22
# The authenticity of host '192.168.2.22 (192.168.2.22)' can't be established.
# ECDSA key fingerprint is 07:e6:10:f7:75:54:9a:58:af:98:97:e1:a8:f6:17:fb.
# Are you sure you want to continue connecting (yes/no)? yes
# Warning: Permanently added '192.168.2.22' (ECDSA) to the list of known hosts.
# root@192.168.2.22's password:
# X11 forwarding request failed on channel 0
# Last login: Fri Aug 2 00:16:57 2013 from 192.168.2.17
# [root@alarmpi ~]#

passwd
# Zaq12wsX
# Enter new UNIX password:
# Retype new UNIX password:
# passwd: password updated successfully

ping www.google.com
# PING www.google.com (74.125.225.177) 56(84) bytes of data.
# 64 bytes from den03s05-in-f17.1e100.net (74.125.225.177): icmp_seq=1 ttl=49 time=60.6 ms
# 64 bytes from den03s05-in-f17.1e100.net (74.125.225.177): icmp_seq=2 ttl=49 time=59.5 ms
# ^C
# --- www.google.com ping statistics ---
# 2 packets transmitted, 2 received, 0% packet loss, time 1001ms
# rtt min/avg/max/mdev = 59.554/60.077/60.601/0.578 ms

pacman -Syu
# :: Synchronizing package databases...
# core 42.5 KiB 299K/s 00:00 [#################################] 100%
# extra 536.2 KiB 632K/s 00:01 [#################################] 100%
# community 546.9 KiB 753K/s 00:01 [#################################] 100%
# alarm 7.1 KiB 77.2K/s 00:00 [#################################] 100%
# aur 19.1 KiB 407K/s 00:00 [#################################] 100%
# :: Starting full system upgrade...
# resolving dependencies...
# looking for inter-conflicts...
#
# Packages (8): cracklib-2.9.0-1 dhcpcd-6.0.4-1 glib2-2.36.3-3
# libgcrypt-1.5.3-1 libusbx-1.0.16-1 linux-firmware-20130728-1
# netctl-1.2-1 pacman-mirrorlist-20130725-1
#
# Total Download Size: 21.26 MiB
# Total Installed Size: 67.06 MiB
# Net Upgrade Size: 1.43 MiB
#
# :: Proceed with installation? [Y/n] y
# :: Retrieving packages ...
# cracklib-2.9.0-1-armv6h 240.8 KiB 350K/s 00:01 [######################] 100%
# dhcpcd-6.0.4-1-armv6h 88.5 KiB 226K/s 00:00 [######################] 100%
#
# --------- 8< ---------------------------- 8< -------------- # # (7/8) upgrading netctl [#####################################] 100% # (8/8) upgrading pacman-mirrorlist [#####################################] 100% pacman-key --init # gpg: /etc/pacman.d/gnupg/trustdb.gpg: trustdb created # gpg: no ultimately trusted keys found # gpg: Generating pacman keyring master key... # gpg: key 69F70C96 marked as ultimately trusted # gpg: Done # ==> Updating trust database...
# gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
# gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u

reboot

pacman -S netctl
# warning: netctl-1.2-1 is up to date -- reinstalling
# resolving dependencies...
# looking for inter-conflicts...
#
# Packages (1): netctl-1.2-1
#
# Total Installed Size: 0.16 MiB
# Net Upgrade Size: 0.00 MiB
#
# :: Proceed with installation? [Y/n] y
# (1/1) checking keys in keyring [###############################] 100%
# (1/1) checking package integrity [###############################] 100%
# (1/1) loading package files [###############################] 100%
# (1/1) checking for file conflict [###############################] 100%
# (1/1) checking available space [###############################] 100%
# (1/1) reinstalling netctl

cd /etc/netctl/
# This is the directory for setting up networking in Arch

install -m640 examples/wireless-wpa wireless-home
# Install does the same thing as cp, but can alter the mode in the transfer.

vi wireless-home
# Set the ESSID and network password, then save the file.

netctl start wireless-home
# If you just get a prompt back, all is well!

# But, because we're paranoid, lets check.
ifconfig
# eth0: flags=4163 mtu 1500
# inet 10.42.0.43 netmask 255.255.255.0 broadcast 10.42.0.255
# ether b8:27:eb:9b:ed:bd txqueuelen 1000 (Ethernet)
# RX packets 1590 bytes 763883 (745.9 KiB)
# RX errors 0 dropped 0 overruns 0 frame 0
# TX packets 958 bytes 125982 (123.0 KiB)
# TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
#
# lo: flags=73
mtu 16436
# inet 127.0.0.1 netmask 255.0.0.0
# loop txqueuelen 0 (Local Loopback)
# RX packets 0 bytes 0 (0.0 B)
# RX errors 0 dropped 0 overruns 0 frame 0
# TX packets 0 bytes 0 (0.0 B)
# TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
#
# wlan0: flags=4163
mtu 1500
# inet 192.168.2.9 netmask 255.255.255.0 broadcast 192.168.2.255
# ether c8:3a:35:ca:41:a1 txqueuelen 1000 (Ethernet)
# RX packets 12 bytes 2010 (1.9 KiB)
# RX errors 0 dropped 0 overruns 0 frame 0
# TX packets 12 bytes 1768 (1.7 KiB)
# TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
#

netctl enable wireless-home
# This enables the connection after a reboot, kind of important. It also spits out
# the rather cryptic message below;
# ln -s '/etc/systemd/system/netctl@wireless\x2dhome.service' \
# '/etc/systemd/system/multi-user.target.wants/netctl@wireless\x2dhome.service'

reboot
# Verify that wireless comes up

ssh root@192.168.2.9

pacman -Syu
# :: Synchronizing package databases...
# core is up to date
# extra is up to date
# community is up to date
# alarm is up to date
# aur is up to date
# :: Starting full system upgrade...
# there is nothing to do

fdisk /dev/mmcblk0
# Welcome to fdisk (util-linux 2.23.2).
#
# Changes will remain in memory only, until you decide to write them.
# Be careful before using the write command.
#
#
# Command (m for help): p
#
# Disk /dev/mmcblk0: 7913 MB, 7913603072 bytes, 15456256 sectors
# Units = sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 512 bytes
# I/O size (minimum/optimal): 512 bytes / 512 bytes
# Disk label type: dos
# Disk identifier: 0x00057540
#
# Device Boot Start End Blocks Id System
# /dev/mmcblk0p1 2048 186367 92160 c W95 FAT32 (LBA)
# /dev/mmcblk0p2 186368 3667967 1740800 5 Extended
# /dev/mmcblk0p5 188416 3667967 1739776 83 Linux
#
# Command (m for help): n
# Partition type:
# p primary (1 primary, 1 extended, 2 free)
# l logical (numbered from 5)
# Select (default p): p
# Partition number (3,4, default 3): 3
# First sector (3667968-15456255, default 3667968):
# Using default value 3667968
# Last sector, +sectors or +size{K,M,G} (3667968-15456255, default 15456255):
# Using default value 15456255
# Partition 3 of type Linux and of size 5.6 GiB is set
#
# Command (m for help): w
# The partition table has been altered!
#
# Calling ioctl() to re-read partition table.
#
# WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
# The kernel still uses the old table. The new table will be used at
# the next reboot or after you run partprobe(8) or kpartx(8)
# Syncing disks.

reboot
# Just for good measure

ssh root@192.168.2.9
# root@192.168.2.9's password:
# X11 forwarding request failed on channel 0
# Last login: Thu Jan 1 00:00:29 1970 from 192.168.2.17

fdisk -l
# Disk /dev/mmcblk0: 7913 MB, 7913603072 bytes, 15456256 sectors
# Units = sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 512 bytes
# I/O size (minimum/optimal): 512 bytes / 512 bytes
# Disk label type: dos
# Disk identifier: 0x00057540
#
# Device Boot Start End Blocks Id System
# /dev/mmcblk0p1 2048 186367 92160 c W95 FAT32 (LBA)
# /dev/mmcblk0p2 186368 3667967 1740800 5 Extended
# /dev/mmcblk0p3 3667968 15456255 5894144 83 Linux
# /dev/mmcblk0p5 188416 3667967 1739776 83 Linux

mkfs.ext2 /dev/mmcblk0p3
# mke2fs 1.42.8 (20-Jun-2013)
# Filesystem label=
# OS type: Linux
# Block size=4096 (log=2)
# Fragment size=4096 (log=2)
# Stride=0 blocks, Stripe width=0 blocks
# 368640 inodes, 1473536 blocks
# 73676 blocks (5.00%) reserved for the super user
# First data block=0
# Maximum filesystem blocks=1509949440
# 45 block groups
# 32768 blocks per group, 32768 fragments per group
# 8192 inodes per group
# Superblock backups stored on blocks:
# 32768, 98304, 163840, 229376, 294912, 819200, 884736
#
# Allocating group tables: done
# Writing inode tables: done
# Writing superblocks and filesystem accounting information: done

echo "/dev/mmcblk0p3 /home ext2 defaults 0 0" >> /etc/fstab
# Set up a directory to store files.

reboot
# Make sure the mount worked

ssh root@192.168.2.9

timedatectl set-timezone America/New_York

timedatectl status
# Local time: Thu 2013-08-08 02:16:42 EDT
# Universal time: Thu 2013-08-08 06:16:42 UTC
# Timezone: America/New_York (EDT, -0400)
# NTP enabled: yes
# NTP synchronized: no
# RTC in local TZ: no
# DST active: yes
# Last DST change: DST began at
# Sun 2013-03-10 01:59:59 EST
# Sun 2013-03-10 03:00:00 EDT
# Next DST change: DST ends (the clock jumps one hour backwards) at
# Sun 2013-11-03 01:59:59 EDT
# Sun 2013-11-03 01:00:00 EST

pacman -S sudo
# resolving dependencies...
# looking for inter-conflicts...
#
# Packages (1): sudo-1.8.7-1
#
# Total Download Size: 0.62 MiB
# Total Installed Size: 2.82 MiB
#
# :: Proceed with installation? [Y/n] y
# :: Retrieving packages ...
# sudo-1.8.7-1-armv6h 635.9 KiB 604K/s 00:01 [###############] 100%
# (1/1) checking keys in keyring [######################################] 100%
# (1/1) checking package integrity [######################################] 100%
# (1/1) loading package files [######################################] 100%
# (1/1) checking for file conflict [######################################] 100%
# (1/1) checking available space [######################################] 100%
# (1/1) installing sudo [######################################] 100%

visudo
# Append 'pi ALL=(ALL) ALL' to the end of the file.

pacman -S motion
# Time to install the actual software that makes this a web enabled web cam.
# resolving dependencies...
# looking for inter-conflicts...
#
# Packages (62): alsa-lib-1.0.27.2-1 damageproto-1.2.1-2 enca-1.14-1
# ffmpeg-compat-1:0.10.8-4 fixesproto-5.0-2 flac-1.3.0-1 fontconfig-2.10.93-1
# freetype2-2.5.0.1-1 fribidi-0.19.5-1 gsm-1.0.13-7 inputproto-2.3-1
# json-c-0.11-1 kbproto-1.0.6-1 lame-3.99.5-1 libass-0.10.1-1 libasyncns-0.8-4
# libdrm-2.4.46-2 libice-1.0.8-1 libjpeg-turbo-1.3.0-2 libmodplug-0.8.8.4-1
# libogg-1.3.1-1 libpciaccess-0.13.2-1 libpulse-4.0-2 libsm-1.2.1-1
# libsndfile-1.0.25-2 libtheora-1.1.1-3 libva-1.2.1-1 libvdpau-0.7-1
# libvorbis-1.3.3-1 libvpx-1.2.0-1 libx11-1.6.1-1 libxau-1.0.8-1
# libxcb-1.9.1-2 libxdamage-1.1.4-1 libxdmcp-1.1.1-1 libxext-1.3.2-1
# libxfixes-5.0.1-1 libxi-1.7.2-1 libxrender-0.9.8-1 libxtst-1.2.2-1
# libxxf86vm-1.1.3-1 mesa-9.1.6-1 mesa-libgl-9.1.6-1 opencore-amr-0.1.3-1
# openjpeg-1.5.1-1 orc-0.4.17-1 recode-3.6-7 recordproto-1.14.2-1
# renderproto-0.11.1-2 rtmpdump-20121230-2 schroedinger-1.0.11-1
# sdl-1.2.15-3 speex-1.2rc1-3 v4l-utils-0.9.5-2 wayland-1.2.0-1
# x264-20130702-2 xcb-proto-1.8-2 xextproto-7.2.1-1 xf86vidmodeproto-2.3.1-2
# xproto-7.0.24-1 xvidcore-1.3.2-1 motion-3.2.12-10
#
# Total Download Size: 16.99 MiB
# Total Installed Size: 89.23 MiB
#
# :: Proceed with installation? [Y/n] y
# :: Retrieving packages ...
# libjpeg-turbo-1.3.0-2-armv6h 265.3 KiB 241K/s 00:01 [###################] 100%
# v4l-utils-0.9.5-2-armv6h 423.5 KiB 453K/s 00:01 [###################] 100%
# alsa-lib-1.0.27.2-1-armv6h 341.0 KiB 35.7K/s 00:10 [###################] 100%
# gsm-1.0.13-7-armv6h 33.9 KiB 131K/s 00:00 [###################] 100%
# ( 9/62) installing fontconfig [#####################################] 100%
# (61/62) installing ffmpeg-compat [#####################################] 100%
# (62/62) installing motion [#####################################] 100%

useradd -m pi
# Create a user for normal logins

passwd pi
# pi
# Enter new UNIX password:
# Retype new UNIX password:
# passwd: password updated successfully

ssh pi@192.168.2.9
# pi@192.168.2.9's password:

mount
# /dev/mmcblk0p5 on / type ext4 (rw,relatime,data=ordered)
# devtmpfs on /dev type devtmpfs (rw,relatime,size=84784k,nr_inodes=21196,mode=755)
# /dev/mmcblk0p3 on /home type ext2 (rw,relatime)
# The line above is good!
# /dev/mmcblk0p1 on /boot type vfat (rw,shortname=mixed,errors=remount-ro)

mkdir -p /home/pi/motion
# Create a place for our stuff

chmod 750 motion
# Make it a little safer.

systemctl enable motion.service
# ln -s '/usr/lib/systemd/system/motion.service' '/etc/systemd/system/multi-user.target.wants/motion.service'

vi /etc/systemd/system/multi-user.target.wants/motion.service

Changing the mount point of a partition

Hi CLUG,

I have an external backup drive. The partition that has my Linux backup files (via rsync) is recognised as

43a15d01-9f3f-4069-bdab-106832d54ff0/

when I plug my removable drive into a usb port on my computer. I tried to rename the partition. This is what I get:

mv 43a15d01-9f3f-4069-bdab-106832d54ff0/ backup/

mv: cannot move `43a15d01-9f3f-4069-bdab-106832d54ff0/' to `backup/': Device or resource busy

I seem to have a catch 22. I can’t rename the partition without plugging it in to my laptop and mounting it.

any ideas?

thanks

Bill


The number you’re seeing is a UUID, or Universally Unique IDentifier, it’s a number that is derived from a number of things, some of which are the date, the MAC address of the machine, and the local random number generator.
The simplest way to rename a filesystem is usually to use gparted (Gnu Partition Editor). First, make sure that the partition you want to rename is plugged in and visible, then issue the command in a terminal.

steve@NV78:~$ sudo mount
[sudo] password for steve:
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)
gvfs-fuse-daemon on /home/stevej/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=steve)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sdb1 on /media/6828-CB13 type vfat (rw,nosuid,nodev,uid=1001,gid=1001,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks)

Just for the sake of argument, let’s say I wanted to rename the SD card from 6828-CB13 to Camera and it is formatted as vfat (last line in the output above), I’d issue:

steve@NV78:~$ sudo gparted

First, make certain that you have selected the correct device (/dev/sdb1 in the upper right corner of gparted), and that it is unmounted (right click on the device in the lower half of gparted). Then, change the label by right clicking the device and selecting Label in the pop-up menu. Finally, make the changes permanent by clicking the green ‘Apply’ checkmark button (upper center), and you should be golden!

GParted-2

GParted

Mass mailing from the command line!

This is the little script that sent out the messages for the picnic!

#!/bin/bash
for Each in ` cat CLUGers.txt `
do cat Message.txt | mutt -s "June CLUG meeting" $Each
echo $Each
sleep 10
done

Message.txt is a file in the local directory that contained the body text of the e-mail, CLUGers.txt is a list of email addresses, one per line of the people we wanted to send the e-mail to.