Sign up here and you can log into the forum!

some scripting help please

General homebrew discussion area

Re: some scripting help please   

Postby recliq » Sat Sep 24, 2011 7:09 am

have you really tried the script exactly how i posted it? i can c&p it to shell and it works...

there's only one mistake i found... the find includes the start dir as well as first entry

here's a corrected version:
Code: Select all
#!/usr/bin/bash
eval `grep 'RANDOM_MENUSHEETDIR=' /conf/config`
[ ! -d "$RANDOM_MENUSHEETDIR" ] && logger -t random_menusheetdir "No such dir: $RANDOM_MENUSHEETDIR" && exit
DIRS=($(find "$RANDOM_MENUSHEETDIR" -maxdepth 1 -type d))
[ ${#DIRS[@]} -eq 0 ] && logger -t random_menusheetdir "No menusheet dirs found" && exit
unset DIRS[0]
RND=$RANDOM
let "RND%=${#DIRS[@]}"
config_tool -c MENUSHEETDIR=${DIRS[RND]}
/osd/etc/init.d/S99menusheets restart
logger -t random_menusheetdir "Changed MENUSHEETDIR to ${DIRS[RND]}"


this really works.. make sure you have no starting whitespaces on any line.
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5025
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: some scripting help please   

Postby PaulF » Sat Sep 24, 2011 11:18 am

KAD wrote:@PaulF, thanks but that also did not work

so on to recliq's bash script, I had to fix some syntax errors to get it to run
KAD
I have been doing perl for a very long time. According to the perl community it is bad form to change someone's perl style because Larry Wall always says, "There is more than one way to do it". I think it is OK to bash a basher, though and it is probably encouraged. :) So here is my take:
Code: Select all
#!/usr/bin/perl
open(CFGFILE,"/conf/config");
while(<CFGFILE>){
   last if ($location) = /RANDOM_MENUSHEETDIR='(.*)'/;
}
close CFGFILE;

if (!opendir(DIR,$location)) {
    system("logger -t random_menusheetdir \'Failed to access $location!\'");
    die;
}

my @menusheetdirectories = grep {-d "$location/$_" && !/^\./ } readdir(DIR);
closedir(DIR);

my $numentries = @menusheetdirectories;         
if ($numentries == 0) {
    system("logger -t random_menusheetdir \'No valid wallpapers found in $location!\'");
    die;
}

my $directory = $menusheetdirectories[int rand $numentries];

system("config_tool -c MENUSHEETDIR=$directory");
system("/osd/etc/init.d/S99menusheets restart");
system("logger -t random_menusheetdir \'Changed MENUSHEETDIR\'");
User avatar
PaulF
Developer
 
Posts: 420
Joined: Sat May 08, 2010 8:34 pm
Location: Oregon

Re: some scripting help please   

Postby KAD » Sat Sep 24, 2011 3:38 pm

@PaulF, I appreciate that and certainly don't mind another point of view on how to do it

I'll give it a try when I have a chance
unfortunately, at the moment, I'd just be happy to have a useable device
shortly after post above last night, I thought a bricked my live
it's still not in a usable state, it's stuck in a cycle, each time I get to the point where I think everything is going to be ok
it wipes 2/3 of my /conf/config
both b-rad and recliq are out of idea's on what is causing this, recliq, suggested, maybe I'm having NAND failure or something like that

as for recliq's script what he just posted above works, it seems when I initially ran it, there was some excess white space causing a syntax error
each time I tried to correct something in it, I just made it worse

so for final working bash script see recliq's last post above, now if I can get myself running, it's time to do some more test before releasing it

KAD
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
User avatar
KAD
Global Moderator
 
Posts: 4015
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Re: some scripting help please   

Postby KAD » Sat Sep 24, 2011 7:37 pm

@recliq, things are working most of the time, here's some more test

from cmd line
Code: Select all
# /osd/etc/init.d/random_menusheetdir
config saved val:key => (MENUSHEETDIR,)
/osd/etc/init.d/S99menusheets: line 1: -n: not found
mount: mounting none on /osd failed: Invalid argument
# /osd/etc/init.d/random_menusheetdir
config saved val:key => (MENUSHEETDIR,/tmp/mnt/E8FA-9D51/MENUSHEETS/Windows-Wallpapers)
# /osd/etc/init.d/random_menusheetdir
config saved val:key => (MENUSHEETDIR,/tmp/mnt/E8FA-9D51/MENUSHEETS/Apple-Wallpapers)

it appears sometimes, no directory is selected

and here's a larger portion of info from messages.txt some of which was started with actual remote power off
Code: Select all
# grep random /tmp/messages.txt
Dec 31 16:29:40 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:29:41 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Action
Dec 31 16:30:29 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:30:30 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to
Dec 31 16:31:02 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:31:02 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Disney-Wallpapers
Dec 31 16:31:35 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:31:35 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Disney-Wallpapers
Dec 31 16:32:07 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:32:07 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to
Dec 31 16:32:38 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:32:39 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Linux-Wallpapers
Dec 31 16:35:16 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:35:16 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to
Dec 31 16:36:09 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:36:09 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to
Dec 31 16:37:57 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:37:58 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Disney-Wallpapers
Dec 31 16:42:11 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:42:13 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to
Dec 31 16:44:04 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:44:05 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to
Dec 31 16:44:40 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:44:41 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Action
Dec 31 16:48:55 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:48:55 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Windows-Wallpapers
Dec 31 16:50:17 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to
Dec 31 16:51:04 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Windows-Wallpapers
Dec 31 16:51:59 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Apple-Wallpapers
Dec 31 16:52:31 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Action
Dec 31 16:53:09 WDLXTV user.notice power.monitor: executing: '/osd/etc/init.d/random_menusheetdir'
Dec 31 16:53:10 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Apple-Wallpapers


there's 5 times in there, that no directory was selected
any idea's, and again thanks for you help

KAD

P.S. anybody wondering, I did get myself back up and running
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
User avatar
KAD
Global Moderator
 
Posts: 4015
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Re: some scripting help please   

Postby recliq » Sun Sep 25, 2011 4:17 am

I think i found the error why there is sometimes an empty dir returned:

In my script I delete the first entry from the array because it's the start dir:
Code: Select all
unset DIRS[0]


insert this line after the above to repack the array so that DIRS[1] becomes DIRS[0] (you shifted the first entry from the array like shift(@array) in perl)
Code: Select all
DIRS=( "${DIRS[@]}" )

:geek:
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5025
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: some scripting help please   

Postby KAD » Sun Sep 25, 2011 10:41 am

well making progress, it still produces some interesting entries

here's the ones that don't work
Code: Select all
Dec 31 16:15:17 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to Scifi-Wallpapers
the value Scifi-Wallpapers, by itself is not valid, needs to be a full path
Code: Select all
Dec 31 16:14:46 WDLXTV user.notice random_menusheetdir: Changed MENUSHEETDIR to /tmp/mnt/E8FA-9D51/MENUSHEETS/Action
should be Action-Wallpapers

any idea's

KAD
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
User avatar
KAD
Global Moderator
 
Posts: 4015
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Re: some scripting help please   

Postby recliq » Sun Sep 25, 2011 11:52 am

do you have dirs containing spaces or special charaters?
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5025
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: some scripting help please   

Postby KAD » Sun Sep 25, 2011 12:04 pm

fixed 1 with a space, but, no special characters

Code: Select all
# ls /tmp/mnt/E8FA-9D51/MENUSHEETS/
ActionScifi-Wallpapers  Cars-Wallpapers          Linux-Wallpapers
Apple-Wallpapers         Disney-Wallpapers        Windows-Wallpapers


I can certainly change everything to an underscore, if that's better
Linux_Wallpapers

KAD
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
User avatar
KAD
Global Moderator
 
Posts: 4015
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Previous

Return to WDTV G2 & WDTV Live homebrew discussion

Who is online

Users browsing this forum: No registered users and 1 guest