Trying to create a script to update inside all my jails.

Wolfeman0101

Patron
Joined
Jun 14, 2012
Messages
428
I was trying to create something I could run that would look for all my jails and run an update/upgrade in each one. This is what I have so far but it's not working. I've never done bash scripting.

Code:
#!/bin/bash
declare -a vars
eval "vars=(`/usr/local/bin/iocage list | awk '{ print $4 }' | sed '2d' | grep .`)"
for i in $vars; do
    /usr/local/bin/iocage exec "${vars[$I]}" "pkg update && pkg upgrade" | grep -q 'Your $var packages are up to date.'
done
 
Joined
Jan 7, 2015
Messages
1,150
You are pretty close as written. Heres what I have with a little more feedback.

Code:
#!/bin/bash
declare -a vars
eval "vars=(`/usr/local/bin/iocage list | awk '{ print $4 }' | sed '2d' | grep >
for ((I = 0; I < ${#vars[@]}; ++I )); do
echo -e "\e[1;31m Starting Update of "${vars[$I]}" \e[0m"
    /usr/local/bin/iocage exec "${vars[$I]}" "pkg update && pkg upgrade -y"
echo -e "\e[1;31m Update of "${vars[$I]}" Complete \e[0m"
done
 
Joined
Jan 7, 2015
Messages
1,150
I suspect the only thing holding up yours might have been the -y after pkg upgrade
 

Wolfeman0101

Patron
Joined
Jun 14, 2012
Messages
428
You are pretty close as written. Heres what I have with a little more feedback.

Code:
#!/bin/bash
declare -a vars
eval "vars=(`/usr/local/bin/iocage list | awk '{ print $4 }' | sed '2d' | grep >
for ((I = 0; I < ${#vars[@]}; ++I )); do
echo -e "\e[1;31m Starting Update of "${vars[$I]}" \e[0m"
    /usr/local/bin/iocage exec "${vars[$I]}" "pkg update && pkg upgrade -y"
echo -e "\e[1;31m Update of "${vars[$I]}" Complete \e[0m"
done
I'm getting this error.
Code:
bkwolfe@Packers:~ % sudo ./update
Password:
./update: line 3: unexpected EOF while looking for matching ``'
./update: line 9: syntax error: unexpected end of file
bkwolfe@Packers:~ %
 
Joined
Jan 4, 2014
Messages
1,644
Interesting and useful. A couple of questions though:

1. Is pkg update required? The reason I'm asking is this extract from pkg help update

It is best practice to ensure your package repository catalogues are up
to date before doing any package installation (via pkg-install(8)) or
upgrades (via pkg-upgrade(8)). However, explicitly running pkg update is
not normally necessary. By default invoking either of pkg install or pkg
upgrade will cause repository catalogues to be updated automatically,
unless disabled by setting REPO_AUTOUPDATE to false in pkg.conf(5).

2. If pkg update is recommended, are additional switches required? The reason for this question is that when I manually upgraded an 11.3 jail the other day, this was the output:

Code:
root@wp-blog:~ # pkg update -f
Updating FreeBSD repository catalogue...
[wp-blog] Fetching meta.conf: 100%    163 B   0.2kB/s    00:01
[wp-blog] Fetching packagesite.txz: 100%    6 MiB   3.0MB/s    00:02
Processing entries:   0%
Newer FreeBSD version for package libXdamage:
To ignore this error set IGNORE_OSVERSION=yes
- package: 1104001
- running kernel: 1103000
Ignore the mismatch and continue? [y/N]: y
Processing entries: 100%
FreeBSD repository update completed. 28812 packages processed.
All repositories are up to date.
 
Last edited:

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,974
2. If pkg update is recommended, are additional switches required? The reason for this question is that when I manually upgraded a 11.3 jail the other day, this was the output:
That's because FreeBSD 11.3 is no longer supported. The -y switch would have allowed the script to continue on and upgraded the packages based on the 11.4 ports tree and it's dependencies.

This is a good example of why I personally don't like automatic upgrade jail scripts. I want to know what's going on with my jail before the upgrade takes place in case the upgrade breaks something so I'm not poking around in the dark trying to figure out why it broke.
 

hertzsae

Contributor
Joined
Sep 23, 2014
Messages
118
The '-y' switch does not work for pkg update with a version mismatch. I updated the jails to 11.4 (with freenas still at 11.3) to get past the prompt.
 
Joined
Jan 7, 2015
Messages
1,150
I didn't realize until now you were running 11, so yeah expect breakage. Mine quietly runs once a month and does it's thing complete and results come in an email. Ymmv. I'm up to date everywhere.
 

SweetAndLow

Sweet'NASty
Joined
Nov 6, 2013
Messages
6,421
Seems really complicated I just did this

Code:
for n in `iocage list -h -q | awk '{print $1}'`; do iocage update $n; sleep 1; iocage pkg $n upgrade -y; done
iocage restart ALL
 

hertzsae

Contributor
Joined
Sep 23, 2014
Messages
118
Seems really complicated I just did this

Code:
for n in `iocage list -h -q | awk '{print $1}'`; do iocage update $n; sleep 1; iocage pkg $n upgrade -y; done
iocage restart ALL
Love the simple solution. I ran into issues with restart when one of the applications didn't shut down properly which failed out the restart All command before the others reset. Borrowing your code, I switched to:
Code:
for n in `iocage list -h -q | awk '{print $1}'`; do iocage update $n; sleep 1; iocage pkg $n upgrade -y; iocage stop $n; sleep 1; iocage start $n; done
iocage list -l

I also take snapshots of all the jail configuration data before I run this.
 
Joined
Jan 4, 2014
Messages
1,644
This is a good example of why I personally don't like automatic upgrade jail scripts. I want to know what's going on with my jail before the upgrade takes place in case the upgrade breaks something so I'm not poking around in the dark trying to figure out why it broke.
I have to agree with you. The version mismatch I referred to broke SSMTP in a number of my jails. I've found the culprit and have resolved the issue, but had I run an automatic upgrade script, the source of the issue might have remained a mystery to me.
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,456
Top