my puppy won't always go to sleep
I've found a way of putting my machine to sleep (so nice, don't have
to boot anymore just to check my mail..), but it's not very
reliable. Sometimes I have to run the script two or three times before
everything shuts down. It looks like the hard drive occasionally spins
up again at the same time that apm --suspend is called. I thought I
could prevent this by calling apm (without the --suspend argument)
earlier in the script in order to "cache" the executable in RAM, but I
guess this doesn't really do the trick. Here's the script, maybe y'all
can give me your $0.02. BTW I do know about apmd, I'm just not using
it because when I tried, weird things happened (don't remember what
they are, sorry). Though if you are using apmd successfully to
accomplish what I'm trying to here, feel free to let me know how you
did it. -chris
#!/bin/sh
PRGNAME=`basename $0`
RUNLEVELFILE=/var/local/${PRGNAME}/runlevel
runlevel | awk '{print $2}' > ${RUNLEVELFILE}
ATTEMPTS=5
COUNT=0
HDD=/dev/hda
stop-processes # send STOP signal to things that need networking
sudo /sbin/telinit 4 # this shuts down networking, noflushd, and gpm
while [ ${COUNT} -lt ${ATTEMPTS} ]; do # keep trying hdparm -y until success
sync
sleep 1
sync
sleep 1
sync
sleep 1
apm >> /dev/null
hdparm ${HDD} >> /dev/null
grep >> /dev/null 2>&1
hdparm -y ${HDD} >> /dev/null
sleep 5
if ! hdparm -C ${HDD} | grep active >> /dev/null; then
break
fi
COUNT=`expr ${COUNT} + 1`
done
apm --suspend
sudo -u root /sbin/telinit `cat ${RUNLEVELFILE}` # resume original runlevel
resume-processes # send CONT signal to processes we had sent STOP to
Reply to: