Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
06-11-2013, 12:06 PM
|
#1
|
LQ Newbie
Registered: Apr 2013
Posts: 20
Rep: 
|
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
|
|
|
06-11-2013, 12:39 PM
|
#2
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
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.
|
06-11-2013, 02:45 PM
|
#3
|
LQ Newbie
Registered: Apr 2013
Posts: 20
Original Poster
Rep: 
|
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?
|
|
|
06-11-2013, 02:46 PM
|
#4
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
like any other command by default it waits unless you background it (&).
|
|
|
06-11-2013, 02:58 PM
|
#5
|
LQ Newbie
Registered: Apr 2013
Posts: 20
Original Poster
Rep: 
|
Awesome!
Thanks for your help. I think I should be able to get this done!
Thank you!
Mike
|
|
|
06-11-2013, 03:29 PM
|
#6
|
LQ Newbie
Registered: Apr 2013
Posts: 20
Original Poster
Rep: 
|
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
|
|
|
06-11-2013, 03:32 PM
|
#7
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
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.
|
|
|
06-11-2013, 03:38 PM
|
#8
|
LQ Newbie
Registered: Apr 2013
Posts: 20
Original Poster
Rep: 
|
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?
|
|
|
06-11-2013, 03:51 PM
|
#9
|
Senior Member
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,992
|
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.
|
06-11-2013, 03:54 PM
|
#10
|
Senior Member
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,992
|
Quote:
Originally Posted by mspear20
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.
|
06-12-2013, 07:24 AM
|
#11
|
LQ Newbie
Registered: Apr 2013
Posts: 20
Original Poster
Rep: 
|
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.
|
|
|
06-12-2013, 02:38 PM
|
#12
|
Senior Member
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,992
|
Quote:
Originally Posted by mspear20
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.
|
06-12-2013, 02:46 PM
|
#13
|
LQ Newbie
Registered: Apr 2013
Posts: 20
Original Poster
Rep: 
|
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?
|
|
|
06-12-2013, 04:10 PM
|
#14
|
Senior Member
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,992
|
Quote:
Originally Posted by mspear20
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.
|
|
|
06-12-2013, 04:43 PM
|
#15
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
Quote:
Originally Posted by mspear20
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.
|
|
|
All times are GMT -5. The time now is 10:54 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|