You are not logged in.
*I'll be very grateful to whoever correctly answers this question, since I need to use this script tonight*
Here's a quick script I've written to help me adjust to polyphasic sleep (please don't start asking me about that here - if you've got questions, make a post in off-topic and I'll answer them ).
I want the script to stay running permanently, continuously listening for my input, and adjusting $DELAY accordingly, then restarting the function 'sleeping'.
The problem is, once I call 'sleeping', there's simply nothing on the screen, as the whole script waits for the 'sleep' bit in 'sleeping' to finish.
Is there some way I can background the 'sleeping' function, so that my 'while' loop will still execute, even while 'sleeping' is running?
Also when this backgrounding is achieved, I only want one instance of 'sleeping' running at any time - if I call 'sleeping' again, will it stop the instance of 'sleeping' that was running beforehand?
#!/bin/bash
if [ $UID != "0" ]; then
echo "You must run this script as root." 1>&2
exit
fi
sleeping() {
sleep $1m
alsactl restore
play /home/.sounds/alarm.mp3
DELAY=60
sleeping $DELAY
}
DELAY=60
sleeping $DELAY
while [ "1" -lt "2" ]
do
clear
echo "1. I'm awake"
echo "2. I'm going for a nap"
echo "3. I'm going out"
echo "4. I'm back"
echo "n"
echo -n Current Time:
date +%k:%M:%S
echo "n"
echo Time Remaining: $DELAY minutes
read -e $input
done
if [ $input = "1" ]
then
DELAY=60
sleeping $DELAY
elif [ $input = "2" ]
then
DELAY=35
sleeping $DELAY
elif [ $input = "3" ]
then
DELAY=999999
sleeping $DELAY
elif [ $input = "4" ]
then
$DELAY=60
sleeping $DELAY
fi
.oO Komodo Dave Oo.
Offline
no. bash does not have "threading".
you need to use a more robust language (python.ruby,etc)..
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
no. bash does not have "threading"
I guess I knew that I was asking for threading, I just didn't want to admit it.
Balls... I'll do it in python then. Time for Dive Into Python again :?
.oO Komodo Dave Oo.
Offline
I decided to do it by just using a pair of scripts instead, where one of the scripts is the function in my original script.
However, I can't for the life of me understand why this doesn't change the variable DELAY when a number is put in. (Note - the script has many more parts than this, but this is the structure that isn't functioning correctly). Any clues?
#!/bin/bash
DELAY=60
while [ "1" -lt "2" ]
do
echo Time Remaining: $DELAY minutes
read -t 5 -e $input
if [ "$input" = "1" ]
then
DELAY=60
elif [ "$input" = "2" ]
then
DELAY=35
elif [ "$input" = "3" ]
then
DELAY=999999
elif [ "$input" = "4" ]
then
DELAY=60
fi
done
.oO Komodo Dave Oo.
Offline
"export DELAY" at the bottom? /shrug
Offline
Change
read -t 5 -e $input
to
read -t 5 -e input
Offline
Change
read -t 5 -e $input
to
read -t 5 -e input
Hehe, what a pillock, of course.. it's always something small.
Many thanks alterkacker
.oO Komodo Dave Oo.
Offline