> My Sun (Solaris 2.6) server is running a program as a listener, when
it
> receives the "installation" command from remote user, it will call a
> script which will automatically reboot the machine, then auto-login,
> then automatically restart the listener to do the installation ...
> Does anyone know how to implement this script,
> Thanks a lot,
Hi
I have a script that does not do exactly what you want, but it
runs a set of scripts that are stored in a certain directory
and runs them in the order they are listed.
The program creates a dummy script that runs before the first
reboot, then it reboots and uses at to reactivate at the
next reboot running the first script. Then it reboots, and
runs the next, and reboots and so on. It may give you an
idea of how it works.
I've tested it on Solaris and Linux (changing the configuration) and
it seems to work OK. Hope it helps.
#!/bin/bash
# We need write permissions over the $SCRIPT_DIR and scripts.
# Scriptnames with trailing ".$SUFFIX" suffix are not supported.
export SCRIPT_DIR="/root/hola/scripts"
# Shell to use to run the scripts.
export SHELL_TO_RUN=/bin/bash
# Shell arguments.
export SHELL_TO_RUN_ARGS=
# export SHELL_TO_RUN_ARGS=-x
# Time to wait in seconds between scripts and shutdowns.
export SCRIPT_DELAY=5
# Time in Seconds.
# Time in minutes that it takes to do a shutdown.
export SHUTDOWN_TIME=2
# Time in minutes.
# Shutdown command
export SHUTDOWN_CMD="sync ; sync ; sync ; /sbin/reboot"
# chmod command.
export CHMOD=/bin/chmod
# mode for shell scripts.
export MODE=700
# rm command.
export RM_CMD=/bin/rm
# tr command.
export TR=/usr/bin/tr
# cut command.
export CUT=/usr/bin/cut
# sleep command.
export SLEEP=/bin/sleep
# at command.
export AT_CMD=/usr/bin/at
# at arguments.
export AT_ARGS="now + $SHUTDOWN_TIME minutes"
# at list.
export AT_LIST="-l"
# Suffix for the new shell scripts. Please include the dot.
export SUFFIX=".cont"
# Name of dummy program to initiate runs.
export DUMMY="Dummy.program"
# * * * * * * From here on there are no user configurable parts. * * * *
* *
cd /
echo "Removing old $0 auxiliary scripts."
$RM_CMD $SCRIPT_DIR/*$SUFFIX $SCRIPT_DIR/$DUMMY 2>/dev/null # Delete the
new shell scripts.
echo "Configuring shell scripts."
export BEFORE="$SCRIPT_DIR/$DUMMY" # Have a dummy program to start.
for name in $SCRIPT_DIR/*
do
echo "$SHELL_TO_RUN $SHELL_TO_RUN_ARGS $BEFORE" >
"$BEFORE$SUFFIX"
echo "$SLEEP $SCRIPT_DELAY" >> "$BEFORE$SUFFIX"
echo "echo $name$SUFFIX | $AT_CMD $AT_ARGS" >> "$BEFORE$SUFFIX"
echo "$SLEEP $SCRIPT_DELAY" >> "$BEFORE$SUFFIX"
echo "echo Pending at commands:" >> "$BEFORE$SUFFIX"
echo "$AT_CMD $AT_LIST" >> "$BEFORE$SUFFIX"
echo "$SLEEP" "$SCRIPT_DELAY" >> "$BEFORE$SUFFIX"
echo "$SHUTDOWN_CMD" >> "$BEFORE$SUFFIX"
echo "$SHELL_TO_RUN $SHELL_TO_RUN_ARGS $name" > "$name$SUFFIX"
echo "$SLEEP $SCRIPT_DELAY" >> "$name$SUFFIX"
echo "$RM_CMD $SCRIPT_DIR/*$SUFFIX" >> "$name$SUFFIX"
echo "$SLEEP $SCRIPT_DELAY" >> "$name$SUFFIX"
echo "$SHUTDOWN_CMD" >> "$name$SUFFIX"
"$CHMOD" "$MODE" "$BEFORE" "$BEFORE$SUFFIX" "$name"
"$name$SUFFIX" 2>/dev/null
export BEFORE="$name"
echo "$BEFORE has been configured."
done
echo "echo" > "$SCRIPT_DIR/$DUMMY" # Only do a dummy instruction in
dummy program.
# Finally beginning execution of the whole thing ;)
echo "Beginning batch routines."
$SHELL_TO_RUN $SHELL_TO_RUN_ARGS $SCRIPT_DIR/$DUMMY$SUFFIX
--
Carlos Plarre
Brainbench MVP for UNIX Admin
Sent via Deja.com
http://www.deja.com/