Posted: Tue May 31, 2011 22:39 Post subject: cd (Change Directory) in a sh script
hi everyone!! i'm sorry if this has been answered in other thread, but i couldn't find any post answering my questions! i've been using dd-wrt for about 5 years now, but i'm a linux/unix noob.
Here's what i got:
- Linksys wrt54g v2 router, with firmware v24 13064 Vintage Std noKaid USB
- USB Mod (http://woodhousellc.com/?p=30)
- Slim Samba 2
- "Optware, the right way" (i need python)
- CoreUtils (installed using ipkg-opt, i need NOHUP)
- 2GB USB stick, with 1 ext3 partition, mounted on /mnt
Here's my problem:
i want a "Wii Media Server" Python script called "Pelis a la Carta" to run 24/7/365 (http://blog.tvalacarta.info/descargas/pelisalacarta-wiimc-3.0.1-python.zip)
so i unzipped it to "/mnt/data/palc" , and if i use telnet and write
nohup python pelisalacarta.py &
it works flawlessly, but i have to start it up after each reboot. so i wrote a "Startup Command"
/bin/sh /mnt/data/palc/palc.sh > /mnt/data/palc/palcout.txt
(the output is only to have a way to check it it was ran or not, can be deleted)
also, it starts using more and more memory when i use my wii to browse movies. so i wrote a cron job to kill it every 20 minutes
/20 * * * * root /bin/sh /mnt/data/palc/palc.sh > /mnt/data/palc/palcout.txt
(the output is only to have a way to check it it was ran or not, can be deleted)
Both, startup command and cron job, start an SH script (palc.sh) that contains the following
the problem is that both run the script, but the script does nothing, if i run the script manually using telnet, i get an error saying this
/mnt/data/palc/palc.sh: cd: line 3: can't cd to /mnt/data/palc
i've tried many different scripts and the problem is always the path-working directory or something, and i can't CD to it or define a PATH or whatever.
i've also tried doing the CD in the startup
everything would work just fine if i could CD within the script, and other linux forums say it's possible.. what am i missing here?? is there anything i shouldn't have installed but did? or should have installed but didn't?? please heeelp!!
your usb drive is not mounted at start, 2nd problem might be that the path to python in unkown. use the full path. _________________ Router: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, wl1: g-Only, WPA-Mixed-Mixed)
WDS Node 1: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, WDS-connected Router, wl1: g-Only WPA-Mixed-Mixed)
WDS Node 2: WRT54GL (g-Only, WPA-Mixed-Mixed WDS-connected to Router)
Modem: Cisco EPC3202
clients: Notebook 1, D-Link 323, PS3 Slim, Kathrein UFC960 connected to WDS Node 1 via Gigabit Switch. Notebook 2, Deskjet 6980 connected to WDS Node 2
and it kinda works, the thing is that it starts pelisalacarta.py, but that py file starts a bunch of other py files, and those files can't be found and throw errors, cuz the "working directory" is still tmp. i guess the python script uses "absolute path" and not "relative path", and i don't want to modify the media server scripts and all the updates they release.
i have optware installed directly on the "root" of the USB drive, one ext3 partition has a "data", "lost+found", and "opt" folders in it. i tried using the 3 partitions, but didn't know how to mount the first partition to opt, and the third to data. so it was all messed up, nothing worked, not samba, not anything..
the shell script was already chmodded to 777, it shows "-rwxrwxrwx"
i also tried the code Zoomlink gave me, it gives a syntax error, so i deleted the "SH" from the code since its a python script and not a shell script that im trying to run from there. it doesn't work either.
any other ideas?? its something about the CD command, because thats the only thing that doesn't work, and i can't CD to any other directory, not /mnt or /opt or /tmp...
If you look in Frater's OTRW thread you will find what you need to do in order to always mount your partitions in the same order.
Since you already shoudl have an /opt/etc/automount file, it may just be a function of changing that file and restarting your router so it automagically picks up the mount points the way you want them and memorializes them for all future reboots and/or changes to automount.
Another thought, since you have Optware installed, have you tried using #!/bin/bash for your script?
Unfortnately, I am not too familiar with Python. But I am at a loss on why cd does not work in your script.
at first it couldn't create the file, so i created an empty file manually, and re-ran the code, and when i used "cat" to check what was in it, i found this
/opt c771d3c0-3d31-43eb-bc37-9de2c54436fd ext3
i used "service automount" to check it's status, and it said that /opt was in automount but /mnt wasn't so i edited the automount file, copy-pasted that single line into a new second line, but changed "/opt" to "/mnt", now if i check the automount status it says /mnt is being mount with automount
then i tried to run my shell script... same error!! =( if i run it with BASH instead of SH it says "no such file or directory"
well.. it works now!!! after reflashing and resetting the router, formatting the USB stick and reinstalling OTRW a few times i came to the conclusion that definetly it wasn't OTRW issue, but the script itself.
so i installed OTRW, Slim Samba2 and PYTHON. i "uploaded" the server script, and started playing with the script again. then i thought "why don't i see what the script that install OTRW does???", so i did, started stripping it down, and after deleting some huge chunks of code, and some iterations, it ended up like this
note that at the end of PATH y added the folder containing the media server script, note the colon at the end of the CD line as well. and also, im telling it where to put the nohup output file, so i can delete it later with another line of the script, so it will be cleaning its own mess. if i start the script manually it throws some "warnings"/errors, but it works!!
after that, the SH script could be started by the startup command or the cron job from my first post, and both would (kill and re)start the media server so its always always running!!!
then the problem was that the router only has 16MB of ram, so after a little bit of "movie browsing" it was suuuuper slow, fixed it by adding and configuring a SWAP file in the same USB stick! now everything works like a champ!!
now i can sit, turn on the wii and have more than 2000 movies and hundreds of series right there on my TV.. anytime, without doing anything else but choosing what to watch.... think of netflix, but free, and with 100 times more satisfaction!!
thank you, everybody!!
IF (only IF) youre going low on space on your router you can delete all the images from all the folders within that zip, also delete all the subfolders in the folder "platform" named after platforms you wont use, except for "developer" (for wii only leave "developer" and "wiimc" ). and then upload it to your router. none of all those files are needed at all!
its a python script, so you need to have python installed (sorry for stating the obvious)
to make it work with the wii you need to have " homebrew channel" on the wii, and an app called "WiiMC" (Wii Media Center)
WiiMC has an "online media" part, where you can find streamin radio stations and some movies, but honestly i didn't find any good "channel" for movies and tv, only music.
WiiMC runs from a SD card, in the SD card, along with the application, theres a file called "online media.xml" or something like that, edit it adding a new link to "pelis a la carta" using the LAN IP of your router running the script and the port configured in the file "resources/settings.conf" of the server files.
you can also check the port used if you run the script using telnet without "nohup" (just "python pelisalacarta.py") it will say something like "servidor iniciado en : IP:PORT" (server started at : IP:PORT)
example of the line to add to "online media.xml" :
<link name=”Pelis a la carta” addr=”http://192.168.1.1:8080″ type=”playlist”>
use the WiiMC version 1.1.7, the latest version, 1.1.8, throws an error using "pelis a la carta"
now put the SD card on the wii, start WiiMC, select Pelis a la carta from Online Media, and go to "Canales", spanish for "channels". there youll find several "channels" which are compilations of media found on different sites, the one i like the most is a channel called "CUEVANA" (media from the Argentinian site "www.cuevana.tv", which is awesome, by the way), you can find that channel under both, "Peliculas" and "Series"
right now cuevana has more than 2000 movies, and more are added every week, and a whole lot of series, updated regularly (episodes are usually uploaded the very same day of the TV release in the US)
what the server really does is grab the links to files hosted on megaupload, hotfile, etc. from those movies sites, and send them to the wiiMC, just the "playlist". WiiMC downloads it from megaupload and plays it.
unfortunately most of all this is in spanish, google translator is your friend now!! or you can ask me, im mexican, i can help you too!! cuevana movies are in the original language, some other channels are in spanish
i hope everything is clear enough as i wrote it, if it's not just tell me and i'll try to be clearer!! xD