SOLVED Help with a script to update jails

Status
Not open for further replies.

mow4cash

Contributor
Joined
Jan 20, 2017
Messages
132
I have this script set up as a cron job running as root. plexpy works fine but that is because /usr/local/etc/rc.d/plexpy has nobody:wheel permissions. How can I make the others work with root:wheel permissions? Does my script look ok?

Code:
#!/bin/bash
for JAIL in Sonarr Radarr Jackett Plex Transmission Plexpy
do
  jexec $JAIL pkg upgrade -y
done
for SERVICE in sonarr radarr jackett plexmediaserver transmission plexpy
do
  jexec -u root $JAIL service $SERVICE restart
done

### Parameters ###
logfile="/tmp/jail_update.tmp"
email="myemail@gmail.com"
subject="Jails update for FreeNAS"


### Set email headers ###
(
	echo "To: ${email}"
	echo "Subject: ${subject}"
	echo "Content-Type: text/html"
	echo "MIME-Version: 1.0"
	echo -e "\\r\\n"
) > ${logfile}

### Set email body ###
(
	echo "<pre style=\"font-size:14px\">"
	echo "##### Jails Updated #####"
	echo "$JAIL"
) >> ${logfile}

### Send report ###
sendmail -t < ${logfile}
rm ${logfile}
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Does my script look ok?
No. Your second for loop doesn't run until your first is complete, so it only runs with the value of $JAIL set to Plexpy. I'm 99% sure that's your problem. And since your script is running as root anyway, there's no need for the -u root on the second jexec command.
 

mow4cash

Contributor
Joined
Jan 20, 2017
Messages
132
No. Your second for loop doesn't run until your first is complete, so it only runs with the value of $JAIL set to Plexpy. I'm 99% sure that's your problem. And since your script is running as root anyway, there's no need for the -u root on the second jexec command.
Yep that did it. I did done done. Not very eloquent but it works for now.
 
Status
Not open for further replies.
Top