Reply
Thread Tools
Posts: 230 | Thanked: 302 times | Joined on Oct 2009 @ Helsinki, Suomi (Finland)
#1
Probably quite a few of us have created shell scripts for our N9's to help with different tasks and to increase usability of our devices. Idea of this thread is to share what you have in your ~/bin and maybe some people will find these scripts useful and/or can improve on them.
 

The Following 3 Users Say Thank You to ladoga For This Useful Post:
Posts: 230 | Thanked: 302 times | Joined on Oct 2009 @ Helsinki, Suomi (Finland)
#2
I'll start with a script called "httpshare" which I made to ease sharing files on my N9. It's basically just a helper script for Python's SimpleHTTPServer, but I've found it very useful when I need to quickly access contents of my N9 from another device.

See/Get it here.

Screenshots for impatient:



Installation:
It depends on python so you need to:
Code:
# apt-get install python
Copy the script to your ~/bin (or elsewhere inside your user's $PATH) and give it executable permissions:
Code:
$ chmod 755 ~/bin/httpshare
Usage examples:
Code:
$ httpshare .
$ httpshare ~/MyDocs/Movies
$ httpshare /etc
On the client side, open a web browser and navigate to N9's IP address.

If you want to access the server from WAN (internet) remember to set your router's port forwarding accordingly.

On a mobile "broadband" (2G/3G) it's possible that your ISP uses NAT for IP addresses (your device doesn't have a public IP address) or the port 80 (http) for incoming traffic is blocked. In latter case you might be able to get through using some other port. (set the value of port variable in the script accordingly).

Known issues:
-Python SimpleHTTPServer will spit out some garbage on keyboard interrupt (Ctrl+c). This is harmless other than aesthetically. I didn't find a good way to remove the garbage as it seems to lump almost all of it's output into stderr and thus sending 2 > /dev/null will also get rid of useful output, such as info on incoming connections. If you nonetheless want to make it quiet you can redirect all it's output to /dev/null by replacing the line:
Code:
develsh -c "python -m SimpleHTTPServer $port > /dev/null"
with:
Code:
develsh -c "python -m SimpleHTTPServer $port > /dev/null 2>&1"
-On Harmattan you need to exit using Ctrl+c. Simply closing the parent terminal won't kill the server. This is probably caused by having develsh inside the script to enable access to port 80 for user. (I didn't notice the same behaviour when running the script sans develsh on a linux desktop.)

PS. Code tags on TMO don't work (wrapping of lines), otherwise I would have posted the script into message itself.

Last edited by ladoga; 2013-01-01 at 19:32.
 

The Following 8 Users Say Thank You to ladoga For This Useful Post:
Schturman's Avatar
Posts: 5,339 | Thanked: 4,133 times | Joined on Jan 2010 @ Israel
#3
 

The Following User Says Thank You to Schturman For This Useful Post:
Schturman's Avatar
Posts: 5,339 | Thanked: 4,133 times | Joined on Jan 2010 @ Israel
#4
I have a question.. Instead exiting with Pressing "Ctrl" + c how I can exit with command ?
 
Posts: 230 | Thanked: 302 times | Joined on Oct 2009 @ Helsinki, Suomi (Finland)
#5
Originally Posted by Schturman View Post
I have a question.. Instead exiting with Pressing "Ctrl" + c how I can exit with command ?
Check the PID of the process with:
Code:
$ ps -Af | grep HTTP
and then kill it with:
Code:
$ kill [PID]
Or if you want to kill it with a oneliner:
Code:
$ pid=`pgrep -f HTTP`; kill $pid

Last edited by ladoga; 2013-01-01 at 19:00.
 

The Following User Says Thank You to ladoga For This Useful Post:
Schturman's Avatar
Posts: 5,339 | Thanked: 4,133 times | Joined on Jan 2010 @ Israel
#6
Tell me please if this ok to add this into N9QT ?
Thanks
 

The Following User Says Thank You to Schturman For This Useful Post:
Posts: 230 | Thanked: 302 times | Joined on Oct 2009 @ Helsinki, Suomi (Finland)
#7
Sure, you can use it as you wish.
 

The Following User Says Thank You to ladoga For This Useful Post:
Win7Mac's Avatar
Community Council | Posts: 664 | Thanked: 1,648 times | Joined on Apr 2012 @ Hamburg
#8
I would like to present my new years' gift from thedead 1440 - a desktop toggle for LPM/standby sreen.

Basically its just 2 icons, 1 sh file and 1 .desktop file, but he even made a .deb for it!
All files are here so feel free to modify if requried.
The regarding thread is here, better icons can be found here or here.
Enjoy.
__________________
Nokia 5110 > 3310 > 6230 > N70 > N9 BLACK 64GB
Hildon Foundation Board member
Maemo Community e.V. co-creator, founder and director since Q4/2016
Current Maemo Community Council member

Last edited by Win7Mac; 2013-01-03 at 01:22. Reason: new icons
 

The Following 2 Users Say Thank You to Win7Mac For This Useful Post:
Schturman's Avatar
Posts: 5,339 | Thanked: 4,133 times | Joined on Jan 2010 @ Israel
#9
ladoga, can you help me to create a simple script that can check if SimpleHTTPServer runs or not and if it is running -> command to close, if not running -> start this "httpshare ~/MyDocs/Movies"
I want to create desktop icon for this:
1. one click = check if SimpleHTTPServer run or not and if it is runing -> command to close.
2. second click = check if SimpleHTTPServer run or not and if it is NOT run -> start this "httpshare ~/MyDocs/Movies"

Thanks

Last edited by Schturman; 2013-01-01 at 23:38.
 
Posts: 230 | Thanked: 302 times | Joined on Oct 2009 @ Helsinki, Suomi (Finland)
#10
@Schturman
In above post there was all you needed to know.

Code:
#!/bin/sh
pid=`pgrep -f SimpleHTTPServer`
dir="/home/user/MyDocs/Movies"

if [ -z $pid ]
then
        cd $dir
        develsh -c "python -m SimpleHTTPServer 80"
else
        kill $pid
fi
Basically you just check if the process does not exist ($pid lenght is zero), if true run python SimpleHTTPServer, else kill the process. There's no need to use httpshare script as you're not using any of it's functionality.

Last edited by ladoga; 2013-01-02 at 00:13.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 17:58.