Ok thanks. That's a really nice start. This really would be one of the few things I would need to do on these machines. They get reinstalled yearly but are used for many different types of teaching etc so they can get a bit messed up. That's why having a script to run every now and then would be perfect for me. I used your code and added a bit so I can churn through all the computers currently logged into linux.
#!/bin/bash
echo -----------------------------
echo RESET GRUB TO BOOT WINDOWS XP
echo -----------------------------
#Read list of machines and run commands below
cat list.txt|while read pc; do
#check pc is online
ping –c 1 $pc
Y=$?
#If ping successful connect and rename grub. Problem here is how to run this on remote machines. Maybe use ssh?
if [ $Y –eq 0 ]; then
GRUB=/boot/grub/grub.conf
COUNT=0; grep ^title $GRUB|while read TITLE; do
[ “${TITLE//ows XP/}” = “${TITLE}” ] ||\
#problem with sed part, doesn't seem to change the default value unless default=0, if not 0 it just appends the number or does nothing.
{ sed –i “s|^default=0$ | default=$COUNT| “ $CONF; break; }
((COUNT++)) ; done; exit 0
else
echo “Ping error code $Y on $pc” >> log.txt
fi
done
Not sure how well this would work. First problem I have is that it will only change the default value if it is 0 not if it is anything else. Secondly, running the edit on the machine would mean I needed to connect. In many ways there's no reason why I couldn't just use the code you gave and add it as a cron job. Having it running via the network would just be as a matter of interest and for the sake of learning. Not sure if I could just do something like (which doesn't seem likely):
ssh $pc COUNT=0; grep ^title $GRUB|while read TITLE; do
ssh $pc [ “${TITLE//ows XP/}” = “${TITLE}” ] ||\
In the sense of running via the network, detecting if the machine responds to ping is good but not perfect as it still responds if booting into Windows XP causing some delays. Perhaps there is a way to check for linux instead of pinging?
Anyway, thank you very much for the help, I appreciate it. Already very promissing