Register for the iXsystems Community to get an ad-free experience and exclusive discounts in our eBay Store.

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

Western Digital Drives - The Preferred Drives of FreeNAS and TrueNAS CORE

Wolfeman0101

Senior Member
Joined
Jun 14, 2012
Messages
417
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
 

John Digital

Neophyte Sage
Joined
Jan 7, 2015
Messages
877
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
 

John Digital

Neophyte Sage
Joined
Jan 7, 2015
Messages
877
I suspect the only thing holding up yours might have been the -y after pkg upgrade
 

Wolfeman0101

Senior Member
Joined
Jun 14, 2012
Messages
417
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:~ %
 

John Digital

Neophyte Sage
Joined
Jan 7, 2015
Messages
877

Basil Hendroff

Neophyte Sage
Joined
Jan 4, 2014
Messages
1,310
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,581
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.
 

Wolfeman0101

Senior Member
Joined
Jun 14, 2012
Messages
417
I think it's this.
Still no go
Code:
bkwolfe@Packers:~ % sudo ./update.bash
Password:
./update.bash: line 3: unexpected EOF while looking for matching ``'
./update.bash: line 9: syntax error: unexpected end of file
bkwolfe@Packers:~ %
 

hertzsae

Member
Joined
Sep 23, 2014
Messages
101
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.
 

John Digital

Neophyte Sage
Joined
Jan 7, 2015
Messages
877
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,344
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

Member
Joined
Sep 23, 2014
Messages
101
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.
 

Basil Hendroff

Neophyte Sage
Joined
Jan 4, 2014
Messages
1,310
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

Wizened Sage
Joined
Aug 16, 2011
Messages
11,877
Top