I have a really weird bash script problem that I can not figure out. I actually have two scripts where one calls the other. Here is the first script, which I named "mirror_distro.sh"
mirror_distro.sh
Code:
#!/bin/bash
HOST="ubuntu.osuosl.org"
ROOT="ubuntu"
METHOD="http"
SECTION="main,restricted,universe,multiverse"
ARCH="i386,amd64"
GENERIC_OPTS="--progress --verbose --nosource --passive --ignore-release-gpg"
# Make sure the directory exists
prep_dir() {
if [ ! -d "$1" ]; then
mkdir -p "$1"
fi
}
# Figure out Distribution to download
DIST=`basename $0|cut -f2 -d "_"`
if [ "$DIST" = "distro.sh" ]; then
echo "Error!"
exit 1
fi
LOG="/var/log/$DIST-mirror.log"
# Get Mirror Directory
ABSPATH="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
PATH_ONLY=`dirname "$ABSPATH"`
MIRROR_DIR="$PATH_ONLY/$DIST"
# If distribution has been released, include security and update sections
case "$DIST" in
"intrepid"|"jaunty"|"karmic" )
DIST_ALL="$DIST,$DIST-security,$DIST-updates"
;;
* )
DIST_ALL="$DIST"
;;
esac
# Primary Canonical Repositories
prep_dir $MIRROR_DIR/canonical
debmirror $GENERIC_OPTS \
--method=rsync \
--host=$HOST \
--root=:ubuntu \
--dist=$DIST_ALL \
--section=$SECTION \
--arch=$ARCH \
--getcontents \
$MIRROR_DIR/canonical | tee $LOG
# Set up repo to be trusted
wget -N -P $MIRROR_DIR/canonical/dists/$DIST http://$HOST/$ROOT/dists/$DIST/Release.gpg
wget -N -P $MIRROR_DIR/canonical/dists/$DIST-updates http://$HOST/$ROOT/dists/$DIST-updates/Release.gpg
wget -N -P $MIRROR_DIR/canonical/dists/$DIST-security http://$HOST/$ROOT/dists/$DIST-security/Release.gpg
case "$DIST" in
"intrepid"|"jaunty"|"karmic" )
# Medibuntu Repository
prep_dir $MIRROR_DIR/medibuntu
debmirror $GENERIC_OPTS \
--method=http \
--host=packages.medibuntu.org \
--root=/ \
--dist=$DIST \
--section="free,non-free" \
--arch=$ARCH \
$MIRROR_DIR/medibuntu | tee -a $LOG
wget -N -P $MIRROR_DIR/medibuntu/dists/$DIST http://packages.medibuntu.org/dists/$DIST/Release.gpg
# Virtualbox
prep_dir $MIRROR_DIR/virtualbox
debmirror $GENERIC_OPTS \
--method=http \
--host=download.virtualbox.org \
--root=virtualbox/debian \
--dist=$DIST \
--section="non-free" \
--arch=$ARCH \
$MIRROR_DIR/virtualbox | tee -a $LOG
wget -N -P $MIRROR_DIR/virtualbox/dists/$DIST \
http://download.virtualbox.org/virtualbox/debian/dists/$DIST/Release.gpg
;;
"lucid" )
;;
esac
This script should be fairly self-explanitory. It's really just a complex wrapper script for the debmirror command. For each distribution (intrepid, jaunty, karmic, lucid) I have a symlink to the mirror_distro.sh file called "mirror_$dist". The filename is used to figure out which distribution to mirror. This script works great normally.
Here's a second script I have called "update.sh":
Code:
#!/bin/bash
AP="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
PO=`dirname "$AP"`
RELEASES="intrepid jaunty karmic"
for dist in $RELEASES; do
echo "Updating $dist..."
$PO/mirror_$dist
done
This one should be even more evident. It's simply my "update all distributions" script and is a wrapper for the first script. This script also works perfectly when I run it myself.
Now here's my problem. I added a job to crontab using the command 'sudo crontab -e' and added the following line:
Code:
0 2 * * * /media/repositories/update.sh
Now here's the weird problem. When cron runs this script only the FIRST distribution (intrepid) is executed. The rest of them are not. I know this because the log file timestamps aren't getting updated and if I run the command manually there are little to no updates for intrepid but there are tons of updates for jaunty and karmic. Does anyone have any idea of why this is happening?
Bookmarks