PDA

View Full Version : Shell script



ieuuk
28th October 2004, 01:28 PM
Hi, i am trying to create a simple shell script which will be run by cron and will:
delete a folder
make a new folder
copy a folder from somewhere else to the one thats just been made
and then turn the system off.

What i am trying to make is a way of running a simple backup copy of data from one hard drive to another of a night but i have no idea how to make shell scripts.

Thanks for your help...

ilja
28th October 2004, 01:30 PM
http://fedoranews.org/mweber/rsync/rsync_intro.shtml
I think this is what you want...

The only think that it doesn't make is to shutdown, but it is not hard to add.

ghight
28th October 2004, 01:57 PM
This is a VERY short intro but should be helpful:

Bash Scripting Basics (http://pegasus.rutgers.edu/~elflord/unix/bash-tute.html)

You are in luck! The script you want is extremely easy if you don't want to use variables. To start, open a text editor and type this in:

#!/bin/bash

Then write the exact same thing you would type on the command line into the editor, one command per line. Name it "something".sh and save it. Add it to your crontab and you are done.

rsync is excellent for backups because it will copy only changed files, but since you are deleteing the directory first, it's just as easy to use the 'cp' command. I would still read up on rsync though. Once you get into it you may find it does what you need anyway.

jayemef
28th October 2004, 04:36 PM
Check out http://www.linuxcommand.org/ also. It is pretty useful for anyone who is just getting into shell scripting.

The nice thing about the shell script is that if you know how to do something via the command line, you can use the same method in your script. It will probably be less effieient that way, but you can still get it done, and you don't need to learn the syntax of variables, loops, etc to get it working.

ieuuk
28th October 2004, 10:47 PM
http://fedoranews.org/mweber/rsync/rsync_intro.shtml
I think this is what you want...

The only think that it doesn't make is to shutdown, but it is not hard to add.

Thanks for that - i have tried it out and it works like a dream and is so easy to set up.

ieuuk
28th October 2004, 10:51 PM
Thanks for all the other posts - I have been having a play with shell scripts and have been able to get them up and running - yay!!!