Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 02-07-2011, 07:33 AM   #1
dent
Junior Member
dent began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Jan 2011
Device: kindle 3
automatically sync remote directory to kindle on wlan0 up

hi all,

I asked this on the ##kindle irc channel but didn't get any feedback so i'll try here

What I'm trying to do:
When I switch the kindle on at home, i want it to rsync (over ssh) the contents of a remote folder to the kindle (fwiw, the remote folder holds daily news which calibre downloads for me every morning).

My approach has been to add the following to my /etc/network/interfaces
Code:
iface wlan0 inet dhcp
	# note post-up doesn't execute anything!
	up /mnt/us/local/bin/wlan0-up.sh
The wlan0-up.sh script checks the essid of the current network and if it's the home one, runs rsync over ssh.

I know the script is correct because it works fine when if I ssh into the kindle and run:
/mnt/us/local/bin/wlan0-up.sh

My 2 problems (I care a lot more about 2 than 1):
  • Getting the ESSID: The following 2 commands return an empty string when run automatically via ifup:
    Code:
    ssid=$(iwconfig wlan0 | head -n 1 | awk {'print $4'} |cut -d: -f2 |tr -d \")
    Code:
    ssid=$(wpa_cli status | grep ^ssid=|cut -d= -f2)
    Both of them return the correct essid when run manually from the command line. The following command works for me, both automatically via ifup and manually on the command line but it's not ideal:
    Code:
    grep -q 'ssid=MYESSID' /var/log/wpa_supplicant.wlan0.log
  • SSH'ing: The following simple ssh command does not connect, it simply returns immediately when run automatically via ifup:
    Code:
    ssh -i /path/to/valid/id_dsa  remuser@remhost touch /tmp/test_file
    The same command works fine from the command line. The wlan0-up.sh script also makes sure it restores known_hosts and the id_dsa key before attempting to ssh anywhere so it's not that.
I've tried all sorts of things including sleeping for a while before running iwconfig, running the commands in a loop and sleeping after each failed one for up to 3 minutes and issuing
Code:
dbus-send --system /default com.lab126.wifid.cmConnected
before calling iwconfig.
This is now really winding me up (!) as it shouldn't be this hard. anyone have any thoughts on it or otherwise managed to get the kindle to automatically sync from a remote folder? I currently have to ssh into it and run the script manually.

Thanks!
d

Last edited by dent; 02-07-2011 at 07:35 AM. Reason: clarified a "doesn't work" statement
dent is offline   Reply With Quote
Old 02-07-2011, 01:12 PM   #2
hawhill
Wizard
hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.
 
hawhill's Avatar
 
Posts: 1,379
Karma: 2155307
Join Date: Nov 2010
Location: Goettingen, Germany
Device: Kindle Paperwhite, Kobo Mini
ifup-called scripts might present you a different PATH environment setting than a login shell. Try qualifying the full paths to the executables you use in your script.
hawhill is offline   Reply With Quote
Advert
Old 02-07-2011, 02:15 PM   #3
janvanmaar
Addict
janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.
 
Posts: 219
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
Wouldn't it be simpler to run a small background script on your remote that would check periodically whether there the Kindle is up and sync when possible? I am actually doing exactly that. One advantage of this approach is that the syncing can be attempted as soon as the directory content changes, not just on the Kindle network start.

EDIT: to your problem 2: perhaps running in the background (& at the end of the command) could help?

Last edited by janvanmaar; 02-07-2011 at 02:25 PM.
janvanmaar is offline   Reply With Quote
Old 02-07-2011, 03:38 PM   #4
dent
Junior Member
dent began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Jan 2011
Device: kindle 3
thanks for the suggestions Jan,

I do use absolute paths in my scripts so it shouldn't be that.
I'd also tried running the scripts in the background and that hadn't helped either.

As to your suggestion, I'd prefer to initiate the sync from the kindle as the remote server is outside my nat'ed network and would require opening and forwarding ports which i'd rather not unless I have to. Especially as pulling from the kindle should be relatively simple thanks for the help though!
dent is offline   Reply With Quote
Old 05-17-2011, 10:03 AM   #5
elementz
Member
elementz began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Dec 2010
Device: kindle
Quote:
Originally Posted by janvanmaar View Post
Wouldn't it be simpler to run a small background script on your remote that would check periodically whether there the Kindle is up and sync when possible? I am actually doing exactly that. One advantage of this approach is that the syncing can be attempted as soon as the directory content changes, not just on the Kindle network start.

Actually, I was looking for a script that exactly does what yours does. Would you mind sharing yours with the community? Thanks in advance :-)
elementz is offline   Reply With Quote
Advert
Old 05-17-2011, 06:06 PM   #6
janvanmaar
Addict
janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.
 
Posts: 219
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
Hi elementz,
well, in the meantime, I am using a modified and significantly more complicated script (in fact a combination of 2 scripts) as I included fetching feeds via calibre in predefined times in it and syncing these particular feeds whenever needed rather than syncing a directory. I tried to find an old backup of the original directory syncing but I could not find it anymore...
However, in case you are under Linux/Unix, it should be easy for me to write you a new script that does a simple directory syncing (if you do not mind that it wouldn't be tested and might need some modifications). A Windows (or multiplatform) or more robust solution would require more time and effort.
janvanmaar is offline   Reply With Quote
Old 05-19-2011, 06:50 AM   #7
elementz
Member
elementz began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Dec 2010
Device: kindle
Hey janvanmaar,

thank you very much for the kind offer!
I am indeed on linux. What I am trying to do is actually the same as you are doing right now: fetching particular feeds, e.g. two times a day, and send them to the kindle as soon as it gets online.
My main problem is that I simply don't know where to start when it comes to pushing the files to the kindle via wlan. What will I need to be running on the kindle?
I guess I'll need to jailbreak first, and have some script running on the kindle to receive the files, right? Or can I simply install ssh, and login to the device over wireless and then push the files over a ssh connection?
If you have your current script at hand, I guess that would be fine, I'd just need something that I can look at for reference.
elementz is offline   Reply With Quote
Old 05-19-2011, 05:18 PM   #8
janvanmaar
Addict
janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.
 
Posts: 219
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
Ah, I see. You'll need to install jailbreak and usbnetwork and setup usbnetwork for shared key ssh access to the Kindle (be careful there). The NiLuJe's README_FIRST.txt file from the usbnetwork package guides you through the process.
That's all needed on the Kindle's side. I am attaching my scripts that I use for automatic feeds downloading at specified times (using Calibre's command line tools) and syncing with the Kindle (using rsync). At the very least, you will need to adjust the settings (before the dashed "END OF INPUT" line) in both the scripts for your situation. I am simply having both the scripts sitting in /usr/local/bin/ and starting the kindle_fetch.py one at boot of the computer.
Attached Files
File Type: gz kindle_feed.tar.gz (20.0 KB, 236 views)
janvanmaar is offline   Reply With Quote
Old 05-20-2011, 03:22 AM   #9
proDOOMman
Enthusiast
proDOOMman can extract oil from cheeseproDOOMman can extract oil from cheeseproDOOMman can extract oil from cheeseproDOOMman can extract oil from cheeseproDOOMman can extract oil from cheeseproDOOMman can extract oil from cheeseproDOOMman can extract oil from cheeseproDOOMman can extract oil from cheeseproDOOMman can extract oil from cheese
 
proDOOMman's Avatar
 
Posts: 32
Karma: 1178
Join Date: Apr 2011
Device: Kindle 3
Quote:
Originally Posted by janvanmaar View Post
Ah, I see. You'll need to install jailbreak and usbnetwork and setup usbnetwork for shared key ssh access to the Kindle (be careful there). The NiLuJe's README_FIRST.txt file from the usbnetwork package guides you through the process.
That's all needed on the Kindle's side. I am attaching my scripts that I use for automatic feeds downloading at specified times (using Calibre's command line tools) and syncing with the Kindle (using rsync). At the very least, you will need to adjust the settings (before the dashed "END OF INPUT" line) in both the scripts for your situation. I am simply having both the scripts sitting in /usr/local/bin/ and starting the kindle_fetch.py one at boot of the computer.
Looks interesting.
I use Unison for synchronization. It slowly than rsync, but can two-side file-synchronization.
proDOOMman is offline   Reply With Quote
Old 05-20-2011, 06:21 AM   #10
janvanmaar
Addict
janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.
 
Posts: 219
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
I actually prefer one-side synchronization only for the Kindle but Unison looks very interesting for other purposes - thanks for useful information!
janvanmaar is offline   Reply With Quote
Old 05-20-2011, 09:26 AM   #11
elementz
Member
elementz began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Dec 2010
Device: kindle
janvanmmar, thx a lot! :-) Really looking forward to set this up, as soon as I have some spare time.
elementz is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Kindle Automatically Doubles Image Sizes wallcraft Amazon Kindle 5 04-01-2011 11:59 AM
Automatically Add Books to Calibre from Directory pjd6896 Calibre 0 12-02-2010 09:15 PM
Is there a way to have Calibre automatically sync my library with my Kindle DX? St-Ambroise Calibre 1 09-05-2010 12:20 AM
Remote Kindle Indexing on PC. vugtitan Amazon Kindle 17 09-02-2010 05:17 PM
Multicomputer Sync users - Do you sync the Config directory? Starson17 Calibre 4 07-29-2010 01:07 AM


All times are GMT -4. The time now is 09:06 PM.


MobileRead.com is a privately owned, operated and funded community.