Bash: bad substitution

I was working on a bash script that uploads a file via sftp and appends a suffix to the filename. The suffix, in this specific case, should have been the date in %y-%m-%d_%H%M%S format.

I’m still a newbie with bash scripting and I used this command to upload and rename the file:

put $file $remote_dest_dir/$remote_filename${date +"%y-%m-%d_%H%M%S"}

Bash complained about a “bad substitution” on that line.

Curly braces are used for different types of parameter expansion and one of the simplest involves the expansion of the value of a variable. The date command inside the braces it’s not a valid parameter or any other expansion, so the shell complains.

I guess that what I really needed was a substitution:

$(date +"%y-%m-%d_%H%M%S")

I replaced the curly braces with regular parenthesis and everything worked like a charm.

Convert ppk to OpenSSH keypairs

.ppk files are created by PuTTY to store a private key generated by the program.

To convert keypairs, first you need to install the package putty and then:

Generate the private key:

puttygen id_rsa.ppk -O private-openssh -o id_rsa

Generate the public key:

puttygen id_rsa.ppk -O public-openssh -o id_rsa.pub

Enable SFTP on Solaris 11

Once you’ve installed an OpenSSH server, you also have an SFTP server. In Solaris, you should check if the subsystem is configured properly or not.

Configuration is stored in /etc/ssh/sshd_config file:

# sftp subsystem
Subsystem       sftp    internal-sftp
PubkeyAuthentication    yes

Restart the service:

svcadm refresh svc:/network/ssh:default

Solaris basics: boot environments

Solaris 11 uses ZFS as root files system.

It all started with a product called Live Upgrade, supporting alternate boot environments (ABEs), a copy of the root file system that can be used as alternate boot devices.

With BEs it’s the same except you don’t need additional partitions. You use ZFS’s snapshots to capture a point-in-time view of the file system.

Two tools mange BEs:

  • Package Manager GUI
  • beadm utility

The beadm utility supports these subcommands:

  • activate
  • create and destroy
  • list
  • mount and unmount
  • rename
elena@solaria:~$ beadm list
BE Name          Flags Mountpoint Space   Policy Created
---------------- ----- ---------- ------- ------ ----------------
solaris          -     -          488.91M static 2019-01-08 09:47
solaris-1        NR    /          4.58G   static 2019-01-08 17:08
solaris-backup-1 -     -          137.43M static 2019-01-08 16:38

NR indicates the active BE (N) and the active BE after reboot (R).

On x86 systems, activating a new BE will update the GRUB menu:

elena@solaria:~$ bootadm list-menu
The location of the boot loader configuration files is: /rpool/boot/grub
default 2
console graphics
timeout 30
0 Oracle Solaris 11.4
1 solaris-backup-1
2 solaris-1

The ZFS file system duplicates the original data blocks and updates the duplicate with the changes.

Destroying a BE releases the metadata that reference its data blocks.

beadm utility can also create snapshots of a BE:

beadm create [name]@[name]

To list snapshots:

beadm list -s

To destroy a BE:

beadm destroy [name]

If any snapshots are associated with the BE, they’ll be removed automatically.

Managing BEs is a side task for the Package Manager.

Solaris basics: booting process on x86 systems

On x86, the boot model relies on the BIOS. x86 systems instead of using a VTOC, use MBR.

X86 counterpart to the OPB’s utility is GRUB.
Solaris 11 uses a modified version of GNU GRUB 0.97.

The variable bootfs locates the file system reader.
kernel$ locates the kernel with additional parameter.
module$ locates the boot archive.

Once you start the boot process, either from OBP or a GRUB, the remaining phases are the same:

  • Booter phase: boot archive file gets read, identified by the bootfs variable
  • Ramdisk phase: an ISO is mounted and used as a stand-alone, read-only file system. It contains configuration files and drivers.
  • Kernel phase: mounts to the ramdisk ans reads driver modules. One of those drivers supports root file system and can attach it to the root device specified. Kernel unmounts from the ramdisk and continues working on the root file system.

The boot archive is a collection of files derived from the full root ( / ) file system of a Solaris 11 instance.
When you install Solaris 11, the system creates the archive by copying key files from /.
The archive must be in sync with root file system; this task is performed automatically during a graceful shutdown process.

Continue reading “Solaris basics: booting process on x86 systems”