danb35
Hall of Famer
- Joined
- Aug 16, 2011
- Messages
- 15,504
Had an offline question about a simple script I prepared to update my jails. On the off chance the discussion would be helpful to anyone else (and on the greater chance I've made errors that need correcting), I'm answering here.
Sure. Here's what I've done with my script now:
The first part is unchanged, of course; the added parts restart the services I want to restart. To break it down a bit further:
Sure. Here's what I've done with my script now:
Code:
#!/bin/bash for JAIL in boinc caddy downloaders plexconnect plexmediaserver urbackup rclone do jexec $JAIL pkg upgrade -y done jexec plexmediaserver service plexmediaserver_plexpass restart for SERVICE in couchpotato sabnzbd sonarr transmission do jexec downloaders service $SERVICE restart done
The first part is unchanged, of course; the added parts restart the services I want to restart. To break it down a bit further:
- The first line simply specifies what interpreter will be used to run the script. Bash is one of many shells available (and, of course, many other interpreters--like python and perl--aren't shells at all). It's very popular on Linux, perhaps somewhat less so on FreeBSD. It can be scripted pretty easily, so that someone like me who doesn't know scripting very well can get it working.
- The next four lines are a
for
loop. That loop steps through the line(s) that follow for each value specified. The general form isfor VALUE in RANGE; do
whatever. It's probably most common that RANGE is numeric, but it can also be a set of strings, as it is in this case. In this case, I've specified the names of each of my jails, and for each of them, I'm runningjexec $JAIL pkg upgrade -y
. - The
jexec
command runs a command inside a jail. It takes two arguments: the name or number of the jail, and the command to run. I'm using jail names, because the numbers can change (if you restart a jail, its number changes). - The command I'm running inside each jail is
pkg upgrade -y
.pkg upgrade
upgrades all installed packages, while-y
tells it to answer Yes to every confirmation question. - After that for loop is complete, the next command is
jexec plexmediaserver service plexmediaserver_plexpass restart
. From the discussion above, you know that this is running the commandservice plexmediaserver_plexpass restart
inside the plexmediaserver jail. Theservice
command allows you to control various services running on a *nix system. It takes two arguments: the name of the service, and what you want to do to that service. In this case, the name of the service is plexmediaserver_plexpass, and I want to restart it. - ...and from the discussion above, it's probably clear what the second for loop does.
Last edited: