LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-13-2013, 05:42 PM   #1
Peterken
Member
 
Registered: Apr 2007
Location: Belgium
Distribution: Debian
Posts: 68

Rep: Reputation: 20
Script to conditionally copy from network


Hi guys,

Currently I'm using the autostart file to get a few things done but this is to restricted.
One of the commands is to copy some files from a networklocation so the local version of these files are always up-to-date and the system is not depending on the network.
Of course this should have gone wrong once because of network not available so now I would like to have a script that checks the availability of the network.
If present, the system should delete the local version of a few files.
If network source is not present, no files have to be deleted and just continue.
My scripting knowledge is mainly wintel based and if someone could pull this out of his sleeve, I would appreciate it big time (have no time/energy to figure this out right now)
I do know about the first line in scripts + how to make the script executable.

One other question regarding on how to create a script: is it not possible on linux to run a script by typing the commands just like in windows?

If there is a better way to synchronize a folder in one direction, that's more then welcome. I have searched for this but didn't find a way to get this done.

TIA!
 
Old 08-13-2013, 06:00 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
Quote:
Originally Posted by Peterken View Post
If there is a better way to synchronize a folder in one direction, that's more then welcome.
There is: rsync

You didn't say what sort of network protocol is used to communicate with the network server, nor what kind of server it is, so rsync may or may not be a feasible solution. If it's not, more details about the setup are needed in order to make a recommendation or write a sample script.

But yes, scripts can be just a set of commands as typed on the command line, and you can run any script from the command line. It's just like in Windows, only about an order of magnitude better.
 
Old 08-13-2013, 06:03 PM   #3
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
two words


man rsync
 
Old 08-13-2013, 06:06 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
So LQ just wiped my post out. awesome.


Im not going to retype everything I did because im a little PO'ed at LQ for doing that lol, use Puppet. Its designed to be a configuration management utility will work well for this and many other things you may need down the road.

Here is an example manifest of how you would declare a file that is required:

Code:
 file {'testfile':
      path    => '/tmp/testfile',
      ensure  => present,
      mode    => 0640,
      content => "I'm a test file.",
    }
http://docs.puppetlabs.com/learning/index.html

Even has a pre-packaged VM with it already installed you can just deploy and play with.

---------- Post added 08-13-13 at 04:06 PM ----------

Quote:
Originally Posted by Ser Olmy View Post
There is: rsync

You didn't say what sort of network protocol is used to communicate with the network server, nor what kind of server it is, so rsync may or may not be a feasible solution. If it's not, more details about the setup are needed in order to make a recommendation or write a sample script.

But yes, scripts can be just a set of commands as typed on the command line, and you can run any script from the command line. It's just like in Windows, only about an order of magnitude better.


Rsync can work and the update option works sometimes but I have had experiences where rsynd did not pick up changes and update the files correctly due to file locks and other possible issues.
 
Old 08-13-2013, 06:24 PM   #5
Peterken
Member
 
Registered: Apr 2007
Location: Belgium
Distribution: Debian
Posts: 68

Original Poster
Rep: Reputation: 20
Thanks a lot for your suggestions guys!

@Ser Olmy: it's a linux server but since all the clients are win boxes, the share is mounted with cifs.

To add some more details about the situation:
the files in just one folder on the server can be modified/erased/new ones added and the local version should match that.
It's for a kind of kiosk/digital signage that works independently from the network.

I'm using geeqie to diplay jpg files but apparently I have to restart the program to load the new files.
On top of that, the screens go on standby so by rebooting I check for new files & get the standby issue resolved. Maybe not very neat but it works well and I'm always open for improvements. ;-)
 
Old 08-13-2013, 06:46 PM   #6
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by Peterken View Post
Thanks a lot for your suggestions guys!

@Ser Olmy: it's a linux server but since all the clients are win boxes, the share is mounted with cifs.
ok..
Quote:
Originally Posted by Peterken View Post
To add some more details about the situation:
the files in just one folder on the server can be modified/erased/new ones added and the local version should match that.
who is local?
the win boxes?
Quote:
Originally Posted by Peterken View Post
It's for a kind of kiosk/digital signage that works independently from the network.
independent, yet requires a network for 'updates'
Quote:
Originally Posted by Peterken View Post
I'm using geeqie to diplay jpg files but apparently I have to restart the program to load the new files.
looks like geegie is 'unix'
Quote:
Originally Posted by Peterken View Post
On top of that, the screens go on standby so by rebooting I check for new files & get the standby issue resolved. Maybe not very neat but it works well and I'm always open for improvements. ;-)
standby ?
what like a screensaver?
turn that feature off

OK, I think I understand..

you have linux boxes dotted around, they are remotes.
you have clients who want to push jpg images to your remotes
the clients use windows
when they buy a remote from you.
you add a cifs mount, so they can push content ??

hmm, second thoughts I don't understand..

anyway, cron on your remote(s) to get updates
look at power management for the standby issue
display of image?. eog will do that, and I think it will see file changes
client changes, some web interface on your server, they upload and you push
 
  


Reply



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
conditionally deleting lines from file vaibhav_soham Linux - General 1 03-10-2011 05:45 AM
Conditionally change group ID JohnE1 Linux - General 5 01-27-2011 09:34 PM
Bash script to copy all music to new hard drive from multiple network shares. pobrika Programming 2 08-09-2010 11:56 PM
need a script that will copy based on filename and then move to a network share when mrgreaper Linux - Newbie 6 09-27-2009 08:21 PM
Conditionally Setting up Different Network Connections Based on Available Networks c4onastick Linux - Networking 1 09-07-2009 02:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:02 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration