You are not logged in.
Hello Archers,
I'm hoping someone can help me out with this for loop in a startup script;
for FILE in active/*
do
ACTIVE="${FILE##*/}-$(cat $FILE)"
cd $ACTIVE
./start-server-rx.sh $ACTIVE
cd ..
done
The 'cat' command works when run as:
/etc/rc.d/script start
But fails when the system is booted.
The script is in the DAEMONS array in rc.conf without & (launched in foreground)
This issue seems very similar to:
" [SOLVED]custom rc.d script works... except at boot." https://bbs.archlinux.org/viewtopic.php?id=65323
The issue here seems to revolve around the 'cat' command.
A $(cat $FILENAME) fetches the contents of the file when run manually, but is NULL when run at boot time.
I added source /etc/profile to the beginning of the script to establish the environment, but that didn't seem to help.
Attached below is the rc.c script and the start-service-script that it runs (which contains the cat).
Any clues as to why this would work manually and fail at boot would _REALLY_ be appreciated...
johnea
COMPLETE STARTUP SCRIPT and RC.D SCRIPT
THE RC.D SCRIPT:
. /etc/rc.conf
. /etc/rc.d/functions
case "$1" in
start)
stat_busy "Starting Telemetry Daemon"
sudo -u target /home/target/start-setup-rx.sh &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon telemetry
stat_done
fi
;;
stop)
stat_busy "Stopping Telemetry Daemon"
sudo -u target /home/target/stop-setup-rx.sh &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon telemetry
stat_done
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0
THE STARTUP SCRIPT THAT THE RC.D SCRIPT CALLS
#!/bin/bash
# start setup-rx.sh with logging
LOGFILE="setup-rx.log"
PIDFILE="setup-rx.pid"
cd /home/target
echo "---------------------------------------------------------------------------" | tee -a $LOGFILE
echo "$(date) running setup-rx.sh in directory: $(pwd)" | tee -a $LOGFILE
echo "---------------------------------------------------------------------------" | tee -a $LOGFILE
if [ -f $PIDFILE ]; then
echo "$PIDFILE exists - setup-rx.sh already running as $(cat $PIDFILE)" | tee -a $LOGFILE
echo "No action taken" | tee -a $LOGFILE
exit 1
fi
if ! [ -d $RXDIR ]; then
echo "$RXDIR does not exist" | tee -a $LOGFILE
echo "Not starting setup-rx.sh" | tee -a $LOGFILE
exit 2
fi
# start setup process
echo "logging to: $LOGFILE" | tee -a $LOGFILE
for FILE in active/*
do
ACTIVE="${FILE##*/}-$(cat $FILE)"
echo "+ starting server-rx.sh for: $ACTIVE" | tee -a $LOGFILE
cd $ACTIVE
./start-server-rx.sh $ACTIVE
cd ..
done
nohup ./setup-rx.sh >> $LOGFILE &
echo "setup-rx.sh is running as PID $!" | tee -a $LOGFILE
echo $! > $PIDFILE
disown
exit 0
Last edited by android (2011-05-27 03:34:01)
Offline
You could try to use absolute path names in your script. Instead of:
for FILE in active/*
do
...
done
Try:
for FILE in /full/path/to/active/*
do
...
done
Last edited by rockin turtle (2011-05-26 23:41:26)
Offline
You could try to use absolute path names in your script.
Thanks for writing rockin turtle!
I had tried that at one point, in fact the active/ directory is a symlink, so I had even tried using the full path to the destination directory. Neither of these changes helped.
I eventually realized that the file I was trying to cat was only accessible via the user's additional group membership, not the user's primary group.
The sudo -g group option didn't work either.
Something about the permissions of the user, within the login shell, being different from the permissions of the same user during boot time, was the cause of the read failure.
I made the file chmod 0664 instead of 0660 and everything worked at bootup!
I think I could also have solved it by setting the user's primary group (in /etc/passwd) to the group with access permissions, instead of only as an additional group membership. I may try this still.
Thanks again for your reply.
I'll mark this one SOLVED.
johnea
Last edited by android (2011-05-27 03:36:33)
Offline