0

I have recently been experimenting and exposing myself to Linux thanks to the Raspberry Pi, but after a lot of researching, I found a way to sync a folder to all nodes on my local web server. I am learning about clustered environments and how clusters generally work. I had the Pi's so I thought why not feast. :D

Question is however, I have the script onchange.sh to execute it properly so that it syncs to all the other local remote hosts, I need to be in the directory. I am using pyplate as my CMS so directory is /usr/share/pyplate.

How does one achieve this so that when I boot up the Pi's, it automatically changes directory to /usr/pyplate and then runs the script.

Thanks and sorry about the lengthy post, I thought explanation was necessary.

closed as off-topic by lenik, Milliways, Ghanima, RPiAwesomeness, Bex Feb 6 '15 at 8:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – lenik, Milliways, Ghanima, RPiAwesomeness, Bex
If this question can be reworded to fit the rules in the help center, please edit the question.

  • This would fit better on Unix & Linux, as this issue is more of a generic Linux issue than a Raspberry Pi-specific one. – RPiAwesomeness Feb 6 '15 at 0:24
2

There are probably dozens of ways.

I use crontab (man crontab) for this sort of job, others prefer to add an entry in /etc/rc.local just before the final line (exit 0).

crontab is used to schedule jobs. One option is to schedule a job on reboot.

If your script needs to be run as root add it to /etc/rc.local or to the root crontab.

sudo crontab -e

If your script doesn't need to be run as root add it your personal crontab.

crontab -e

The crontab entry should be something like

@reboot (sleep 10; cd /usr/share/pyplate; ./onchange.sh)

The sleep may not be needed. It may need to be increased to allow all external resources to be accessible.

This is one method, there are others.


EDITED TO ADD

To manually run the command you can do something like the following.

Create a file in /usr/local/bin called mysync with the following content

#!/bin/bash
cd /usr/share/pyplate
nohup ./onchange.sh &

Then just type mysync to run the script. The nohup will allow the script to run to completion even if you terminate its parent session.

  • Well ultimately the problem is that this there is a script called onchange.sh that I like using since I have a home brewed web server cluster with 6 nodes with a load balancer (created it too). I want to run this script but if I run it via ssh then when I exit the ssh session, it kills the current process too... Also, in order to run this script, I have to be in /usr/share/pyplate because that's what will be syncing. Any suggestions? :o – ShakeSpear Jan 21 '15 at 7:56
  • Is that a new question? I thought I mentioned a couple of ways of doing it at boot. I'll add a method of doing the same post boot. – joan Jan 21 '15 at 8:30
  • No I was redefining the original. I tried crontab method, I rebooted the server and then created a test file. I trashed pyplate idea and went with something simple. Here is my crontab. The test file created in /usr/share/nginx/www did not sync to the second node. prntscr.com/5vjju2 – ShakeSpear Jan 22 '15 at 9:21
  • That's another question update. I have no idea what all those parameters to onchange.sh do. – joan Jan 22 '15 at 9:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.