You are not logged in.
Pages: 1
Sorry for vague title, but I'm at a loss at exactly what the problem is.
I'm writing a small alarm program to wake me up in the morning for school. I have it working almost exactly like I want it to, where I could stop working on it now and still have it be functional, but I want to figure this out.
Before I go on, the code:
#!/bin/sh
#alarm_set="01:33"
alarm_set="33"
mfile="/home/lucas/Musics/Aphex Twin/Drukqs/1-01 - jynweythek.mp3"
mode=+%S #%I:%M
x=1
echo $mfile
function alarm(){
while [ $(date $mode) != $alarm_set ]
do
sleep 1s
done
if [ $(date $mode) == $alarm_set ]
then
echo "Alarm went off."
vlc /home/lucas/Musics/Aphex\ Twin/Drukqs/*.mp3 & sleep 1m
# vlc $mfile & sleep 1m
kill $!
else
echo "Hmm, something went wrong..."
fi
}
while [ $x = 1 ]
do
alarm &
sleep 1m
done
exit 0
#All the values in this are for testing
When I try to run vlc with the $mfile variable set in the code above, it returns the errors:
File reading failed:
VLC could not open the file "/home/lucas/Musics/Aphex".
Your input can't be opened:
VLC is unable to open the MRL 'file:///home/lucas/Musics/Aphex'. Check the log for details.
File reading failed:
VLC could not open the file "/home/lucas/Desktop/programs/Twin/Drukqs/1-01".
Your input can't be opened:
VLC is unable to open the MRL 'file:///home/lucas/Desktop/programs/Twin/Drukqs/1-01'. Check the log for details.
File reading failed:
VLC could not open the file "/home/lucas/Desktop/programs/jynweythek.mp3".
Your input can't be opened:
VLC is unable to open the MRL 'file:///home/lucas/Desktop/programs/jynweythek.mp3'. Check the log for details.
But if I change the variable to the following:
mfile=/home/lucas/Musics/=bansheebeat=/*.mp3
Or anything else without spaces, it'll work. So the spaces have to be the problem, except that I can put what didn't work with the variable as the file to open after vlc and it will work. I've tried backslash escaping, all kinds of quoting, and can't seem to get it to work.
But, being me, hopefully it'll be something simple and stupid I overlooked. Any help?
Last edited by SlayingDragons (2011-08-28 16:37:49)
Offline
Will quoting it work?
vlc "/home/lucas/Musics/Aphex Twin/Drukqs/*.mp3"
EDIT:
#!/bin/sh
# Usage: $0 10:10
TUNEDIR="$HOME/Downloads"
WAKEUP=06:30
PLAYCOUNT=5
[ -z $1 ] || WAKEUP=$1
alarm() {
TIME=$(date +"%H:%M")
if [[ $TIME == $WAKEUP ]]; then
for COUNT in {1..$PLAYCOUNT}; do
smplayer "$(ls -1 "$TUNEDIR"/*.mp3 | shuf | head -n1)" && sleep 30
done
exit 0
fi
}
while true; do
alarm
sleep 10
done
A simple cronjob would do the job also.
anyhow, I just wrote this rather quickly. Test it out youself if you are gonna use it. Change smplayer, WAKEUP and TUNEDIR variables
If you are going to paste a shell script, please remove any unused variable and format it better. (PS: I am not saying OP's code is badly format, just some that I have to sit down and read it...it make my head hurt)
Maybe codes (scripts) is for machine to run but more importantly it should be readable for human.
Not sure if just me or anyone else, I'd rather give up than trying to understand it.
Ninja EDIT:
if you are new to BASH scripting, you may wanna have a look at http://mywiki.wooledge.org/BashPitfalls
Last edited by krisoijn (2011-08-28 10:51:54)
Offline
Have you tried quoting the variable when passed to vlc?
vlc "$mfile" & sleep 1m
Ryzen 9 5950X, X570S Aorus Pro AX, RX 6600, Arch x86_64
Offline
Will quoting it work?
vlc "/home/lucas/Musics/Aphex Twin/Drukqs/*.mp3"
EDIT:
#!/bin/sh # Usage: $0 10:10 TUNEDIR="$HOME/Downloads" WAKEUP=06:30 PLAYCOUNT=5 [ -z $1 ] || WAKEUP=$1 alarm() { TIME=$(date +"%H:%M") if [[ $TIME == $WAKEUP ]]; then for COUNT in {1..$PLAYCOUNT}; do smplayer "$(ls -1 "$TUNEDIR"/*.mp3 | shuf | head -n1)" && sleep 30 done exit 0 fi } while true; do alarm sleep 10 done
A simple cronjob would do the job also.
anyhow, I just wrote this rather quickly. Test it out youself if you are gonna use it. Change smplayer, WAKEUP and TUNEDIR variables
If you are going to paste a shell script, please remove any unused variable and format it better. (PS: I am not saying OP's code is badly format, just some that I have to sit down and read it...it make my head hurt)
Maybe codes (scripts) is for machine to run but more importantly it should be readable for human.
Not sure if just me or anyone else, I'd rather give up than trying to understand it.Ninja EDIT:
if you are new to BASH scripting, you may wanna have a look at http://mywiki.wooledge.org/BashPitfalls
Yeah, sorry, I'm still pretty new to computers in general. I should have warned that I'm a noob.
And thanks for the code, that makes infinitely more sense.
Oh, and yeah, quoting it worked. I thought I tried that. As I thought, it was something simple and stupid.
edit: I'll go ahead and mark this solved.
Last edited by SlayingDragons (2011-08-28 16:37:12)
Offline
Pages: 1