From: Dale <rdalek1967@gmail.com>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Writing a bash script or thinking about it anyway.
Date: Fri, 25 Dec 2009 17:21:31 -0600 [thread overview]
Message-ID: <4B3548FB.4070609@gmail.com> (raw)
In-Reply-To: <543f3b9c0912221745t1d9bb54cp5eee28aa7dbaf7e0@mail.gmail.com>
Francisco Ares wrote:
> On Tue, Dec 22, 2009 at 3:09 AM, Dale <rdalek1967@gmail.com> wrote:
>
>> Neil Walker wrote:
>>
>>> Dale wrote:
>>>
>>>
>>>> Me again. I'm thinking about writing a bash script that backs up my
>>>> /home directory.
>>>>
>>>>
>>> I use a simple rsync cron job to backup entire servers every hour. Does
>>> the job for me. ;)
>>>
>>>
>>> Be lucky,
>>>
>>> Neil
>>> http://www.the-workathome.com
>>>
>>>
>>>
>> But I wouldn't learn how to write a script that way. I got to start
>> somewhere. This is a good place.
>>
>> Dale
>>
>> :-) :-)
>>
>>
>
> Now I got your point.
>
> I would think on something like this (untested):
>
>
> The command line would be
>
> BackupScriptName FromDirectory ToDirectory
>
>
> #! /bin/bash
> FROM=$1
> TO=$2
> cd $FROM
> for i in * .??*
> do
> if [[ -d "$i" ]] # is it a directory?
> then
> # yes, it is a directory
> if [[ -e "$TO/$i" ]] && [[ -d "$TO/$i" ]]
> then
>
> # on the TO side, the name exists
> # and it is a directory
> cd "$i"
>
> # just to show something
> pwd
>
> # calls recursively this same script
> $0 "$FROM/$i" "$TO/$i"
> cd ..
>
> else
> # didn't existed yet on the TO side,
> # so copy everything
> cp -a $FROM/$i $TO/$i
> fi
> else
> # it is a file, not a directory
> if [[ -e "$TO/$i" ]]
> then
> # the file already exists
>
> # do something to compare the files, like:
>
> # gets size from "ls" result
> SIZE1=`ls -l "$i" | cut -d" " -f5`
> SIZE2=`ls -l "TO/$i" | cut -d" " -f5
>
> if (( $SIZE1!=$SIZE2 ))
> then
>
> # size is different, so copy the file
> cp -a "$FROM/$i" "$TO/$i"
>
> else
> # more tests for differences other
> # than size, like date/time
> # or even MD5SUM
> fi
> else
>
> # file doesn't exist at the "TO" side
> cp -a "$FROM/$i" "$TO/$i"
>
> fi
>
> fi
>
> done
>
>
> Hope this helps
> Francisco
>
After learning a little about scripting I'll give this a once over and
see what I learn. Right now, it's like. . . huh. lol
Thanks.
Dale
:-) :-)
next prev parent reply other threads:[~2009-12-26 0:11 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-22 3:22 [gentoo-user] Writing a bash script or thinking about it anyway Dale
2009-12-22 3:53 ` Francisco Ares
2009-12-22 4:16 ` Dale
2009-12-22 4:32 ` Francisco Ares
2009-12-22 5:02 ` Neil Walker
2009-12-22 5:09 ` Dale
2009-12-23 1:45 ` Francisco Ares
2009-12-25 23:21 ` Dale [this message]
2009-12-22 10:34 ` Jesús Guerrero
2009-12-22 11:20 ` Christian Könitzer
2009-12-22 12:11 ` Jesús Guerrero
2009-12-22 14:21 ` Christian Könitzer
2009-12-22 14:51 ` Alan McKinnon
2009-12-22 15:36 ` Jesús Guerrero
2009-12-22 19:01 ` Stroller
2009-12-23 6:58 ` Dirk Heinrichs
2009-12-22 18:56 ` Stroller
2009-12-22 23:25 ` Willie Wong
2009-12-22 11:16 ` Stroller
2009-12-22 23:30 ` Willie Wong
2009-12-22 15:08 ` Ward Poelmans
2009-12-22 15:39 ` Neil Bothwick
2009-12-22 15:57 ` Ward Poelmans
2009-12-23 0:33 ` [gentoo-user] " »Q«
2009-12-25 23:19 ` Dale
2009-12-27 21:09 ` »Q«
2009-12-23 12:29 ` [gentoo-user] " Alex Schuster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B3548FB.4070609@gmail.com \
--to=rdalek1967@gmail.com \
--cc=gentoo-user@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox