FreeBSD first script
I wrote my first little script on FreeBSD. It is a little script and asks you something about your operating system.
It is another feeling as on Linux
The writing of the first script on FreeBSD is another feeling as in Linux, because this operating system uses other syntax in order to describe the commands.
Linux had taken over some commands from Unix and BSD and does it more comfortable.
And of course you have other commands to check your system. I have installed in FreeBSD an file system like OpenZFS.
The first script
#!/bin/sh
echo "Hello $USER!"
du -sh "$HOME"
echo "=== ZFS-Pool ==="
zpool status -x
if [ "$(id -u)" -eq 0 ]; then
du -sh /var/log
echo "=== Boot Environments ==="
bectl list
else
echo "Hint: for /var/log and bectl you need root rights."
printf "Do you want to run the command doas? (y/n) "
read -r yn
case "$yn" in
y|Y|yes|YES)
doas du -sh /var/log
echo "=== Boot Environments ==="
doas bectl list
;;
*)
echo "Have a good day"
exit 0
;;
esac
fi
What does the script?
The script wants to check the size of the Home directory and the /var/log directory. In most cases you need for the /var/log directory root rights.
For this reason I have add an if question in order to asks the user, do you want to add the root password or not.
In my case I have already added the „doas“ command, the „sudo“ command for FreeBSD.
The „doas“ command allows to enter your user’s password instead of your original root password
The used programs
The printf command
This command asks you for information to the user of the computer. It looks like the command from the programming language C++.
It does the same function in the operating system. In the manual pages there is this description about this command:
The printf utility formats and prints its arguments, after the first, under
control of the format. The format is a character string which contains
three types of objects: plain characters, which are simply copied to stan-
dard output, character escape sequences which are converted and copied to
the standard output, and format specifications, each of which causes print-
ing of the next successive argument.
You want to know more? Here is the link for more details.
zpool
This command and the other are specialised commands for the operating systems of BSD. Here is the extract of the description of the program from the original manual site:
The zpool command configures ZFS storage pools. A storage pool is a col-
lection of devices that provides physical storage and data replication for
ZFS datasets. All datasets within a storage pool share the same space.
See zfs(8) for information on managing datasets.
You want to know more? Here is the link for more details.
bectl
Here is the extract of the description of the program from the original manual site:
The bectl utility manages bootable ZFS clones called boot environments.
Boot envionments allow system changes to be tested safely, as they are se-
lectable directly from the boot loader(8). This utility can create, list,
mount, or jail boot environments. Once the changes have been tested, the
boot environment can be unmounted, activated, renamed, and destroyed.
You want to know more? Here is the link for more details.