LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 06-11-2013, 12:06 PM   #1
mspear20
LQ Newbie
 
Registered: Apr 2013
Posts: 20

Rep: Reputation: Disabled
File share between Raspberry Pi and Ubuntu - Running a script


Hi Everyone,

First I'll start off by explaining what I want to do. I have a Raspberry Pi set up as a surveillance system using motion. Because of the size of the SD card that is in it, It could get filled pretty quickly. So what I want to do is:

1. Network the Pi to an external laptop (via wifi) that has an external HD connected to it.

2. At approx 7pm every night, I would like to run a script (preferably on the pi)

-----1. create a new folder (with the date) on the external HD connected to the laptop.

-----2. Stop the service/program Motion on the Pi

-----3. Copy all the files from the folder on the Pi containing the video files to the remote computers external HD that had the folder just created

-----4. Once completed delete all the files in the folder on the Pi

-----5. Start the service/program Motion

So I guess I have 2 questions here. What and how would be my best option to network my pi to a remote computer with an external drive connected to it. (Samba, NFS, or something else) And could someone possibly help me with the scipt.
That being said, I do know a bit about scripting, and I think I can write most of it myself. I will work on the script and update this with what I have written. If anyone has some pointers that might help me with the script that would be great!

Thank you,
Mike
 
Old 06-11-2013, 12:39 PM   #2
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,820

Rep: Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586
my preference is sshfs.

i would run the commands manually one time and save them to a file... modify the file (substitute variables) and put an entry on your crontab to execute when needed.

the commands you likely need are ssh mkdir date scp rm.
 
1 members found this post helpful.
Old 06-11-2013, 02:45 PM   #3
mspear20
LQ Newbie
 
Registered: Apr 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled
Thank you for the response.

I came up with another question.
For example:
If while the script is executing the scp part, will it wait for the pi to transfer all the files, then execute the next step of the script? Or will it move on to the next step of the script before its done transfering?
 
Old 06-11-2013, 02:46 PM   #4
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,820

Rep: Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586
like any other command by default it waits unless you background it (&).
 
Old 06-11-2013, 02:58 PM   #5
mspear20
LQ Newbie
 
Registered: Apr 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled
Awesome!

Thanks for your help. I think I should be able to get this done!

Thank you!
Mike
 
Old 06-11-2013, 03:29 PM   #6
mspear20
LQ Newbie
 
Registered: Apr 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled
Sorry, Another question I came up with.

Because im using a networked laptop with the external drive. Will everything still execute if the external drive goes to sleep? Like a Western Digital does? Or will it wake up once the script reaches out to it?

-Mike
 
Old 06-11-2013, 03:32 PM   #7
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,820

Rep: Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586
not sure ? never had an external harddrive (except for usb flash drives).

the best thing to do is try it and see.

what happens when it is sleep and you try to copy something to it (will it fail ?/ how long does it take to boot up)

i assume once something tries to read/write to it it'll wake up. else what would be the point of an hd that doesnt store/retrieve info ?

Last edited by schneidz; 06-11-2013 at 03:33 PM.
 
Old 06-11-2013, 03:38 PM   #8
mspear20
LQ Newbie
 
Registered: Apr 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled
Worst comes to worst, couldnt I simply "touch" the drive and use the wait command, maybe 5 seconds, until it is ready and then continue with the script?
 
Old 06-11-2013, 03:51 PM   #9
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,437

Rep: Reputation: 434Reputation: 434Reputation: 434Reputation: 434Reputation: 434
as you are going linux to linux, why not just use rsync to transfer the files via your LAN/WAN it is secure, you can set it up to use keys so you dont have to interact with it and it will automatically restart and correct the transfer if there is any kind of connection issue.

a simple script should do the trick.
 
1 members found this post helpful.
Old 06-11-2013, 03:54 PM   #10
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,437

Rep: Reputation: 434Reputation: 434Reputation: 434Reputation: 434Reputation: 434
Quote:
Originally Posted by mspear20 View Post
Sorry, Another question I came up with.

Because im using a networked laptop with the external drive. Will everything still execute if the external drive goes to sleep? Like a Western Digital does? Or will it wake up once the script reaches out to it?

-Mike
yes both the WD and Seagate drives that power down are a royal PITA to deal with. sadly the only way around it i have found is to put it back to factory settings (NTFS) and run their tools to disable sleep. once you do that, they are then controlled by the OS, not their onboard BIOS.
 
1 members found this post helpful.
Old 06-12-2013, 07:24 AM   #11
mspear20
LQ Newbie
 
Registered: Apr 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled
Hey guys,

Once again, Thanks for the help. I worked on it last night, and got everything working with sshfs. Couple questions I have with sshfs. Will it time out or anything like that after awhile? What if my computer goes to sleep? Would I need to reconnect manually? Also will cron do its thing if the computer is locked? If not Im just going to change the power settings and never have the laptop fall asleep. Its a junky one, I dont really care about degrading the life span of it.

Thanks,
-Mike

Last edited by mspear20; 06-12-2013 at 09:48 AM.
 
Old 06-12-2013, 02:38 PM   #12
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,437

Rep: Reputation: 434Reputation: 434Reputation: 434Reputation: 434Reputation: 434
Quote:
Originally Posted by mspear20 View Post
Hey guys,

Once again, Thanks for the help. I worked on it last night, and got everything working with sshfs. Couple questions I have with sshfs. Will it time out or anything like that after awhile?
it will only timeout, if there is a preset in your sshd on the client side. if that is set to never timeout, then you are set. a better solution would be to have your script umount, mount, umount the sshfs mountpoint each time it performs the backup. then a connection timeout is not an issue due to inactivity.

Quote:
What if my computer goes to sleep? Would I need to reconnect manually?
if the computer goes to sleep and does not have a wake on LAN ability, you will have to manually wake up the remote computer (your laptop) and then allow the script to mount the share as i described above. this way you only have to touch 1 computer, not both.[/quote]
Quote:
Also will cron do its thing if the computer is locked? If not Im just going to change the power settings and never have the laptop fall asleep. Its a junky one, I dont really care about degrading the life span of it.

Thanks,
-Mike
as for locked that all depends on how the OS handles connections. I know my server and Linux workstation as long as they are on and have an active LAN connection I can ssh into them, but then again my workstation (a laptop) unless it is powered off the WiFi connection is persistant.
 
1 members found this post helpful.
Old 06-12-2013, 02:46 PM   #13
mspear20
LQ Newbie
 
Registered: Apr 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled
So my best solution would probably just never have my computer go to sleep or lock. The only thing about mounting and unmounting is the whole password problem right? I would have to disable the password in order to do it that way?
 
Old 06-12-2013, 04:10 PM   #14
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,437

Rep: Reputation: 434Reputation: 434Reputation: 434Reputation: 434Reputation: 434
Quote:
Originally Posted by mspear20 View Post
So my best solution would probably just never have my computer go to sleep or lock. The only thing about mounting and unmounting is the whole password problem right? I would have to disable the password in order to do it that way?
no, again, look at what i have typed.

#1. do not use sshfs, its slower and no better then other options for mounting the share.
#2. look into NFS you are going Linux - Linux after all, use what is native and yes your RPi supports NFS connections. I have one at home for media playback to my TV.
#3. if you setup your share or your sshfs properly you would just use keys, again see above.
#4. write a simple script that does what i told you earlier. problems will be solved as long as the laptop has access to the external HDD.
 
Old 06-12-2013, 04:43 PM   #15
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,820

Rep: Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586
Quote:
Originally Posted by mspear20 View Post
So my best solution would probably just never have my computer go to sleep or lock. The only thing about mounting and unmounting is the whole password problem right? I would have to disable the password in order to do it that way?
as long as the pc is on the server should be accessible.
use ssh with keys to login.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Arch Linux on Raspberry Pi Running XFCE LXer Syndicated Linux News 0 01-15-2013 10:30 AM
Running startup script fails because network share isn't ready (Perforce on Debian) tstein Linux - Software 1 05-21-2012 06:57 PM
Bash script for listing FTP usage as the file name of a file created in each share jojothedogboy Programming 1 12-05-2008 03:35 PM
script to upload backup file to smb share c_mitulescu Linux - Networking 1 03-15-2007 11:34 AM
Running a script file johnlb Linux - Newbie 2 02-19-2003 02:17 AM


All times are GMT -5. The time now is 08:51 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration