if [ -d "/some/dir ]; then
        echo "woo!"
else
        echo "wah."
fi

See.. "man test" for all the details.

M.


On Mon, 29 Jan 2001 at 9:38pm (-0600), Jonathan Wilson wrote:

> Howdy,
>
> I just wrote a bash script for making manual backups easier (I do them
> manually when I'm about to edit something major) it basically makes a
> new directory in /backup/ who's name is equal to today's date, then
> recursively copies certain dirs I want backed up.
>
> The problem is, on some projects I like to do the manual backup each
> time I get to a stable point before making the next few edits. What I'm
> wanting is for the script to check and see if a directory with today's
> date already exists. If it does I want it to append the hour as well as
> the date. Then if there's already on with the same hour it should append
> the minute.
>
> Another option would be for it to add something like _1 to the end and
> increment _1 by one digit each time (_2, _3, _4....) but I like the day,
> then hour, then minute better. I guess we could add seconds for
> amusement's sake.
>
> Anyway, I'm sure I could figure out how to do an if...else loop, I've
> seen examples, but in bash I've never seen an example of checking for
> the existence of a file or dir. Can anyone show me how to do that?
>
> Here's what I have:
>
> #!/bin/bash
> #
> #First find out what today is
> #
> #
> #oldformat: today=$(date +%Y_%m_%d)
> #
> #new format:
> today=$(date +%m-%d-%Y)
> echo "Today is" $today
> mkdir /backup/$today && echo "backup dir $today created"
> cp -a /etc /backup/$today && echo "etc copied"
> echo
> echo "Done"
>
>
> Thanks in advance...
>
> ----------------------------------------------------
> Jonathan Wilson
> System Administrator
>
> Cedar Creek Software
> http://www.cedarcreeksoftware.com
>
> Central Texas IT
> http://www.centraltexasit.com
>
>
>
> _______________________________________________
> Redhat-list mailing list
> [EMAIL PROTECTED]
> https://listman.redhat.com/mailman/listinfo/redhat-list
>

-- 
WebCentral Pty Ltd           Australia's #1 Internet Web Hosting Company
Level 1, 96 Lytton Road.           Network Operations - Systems Engineer
PO Box 4169, East Brisbane.                       phone: +61 7 3249 2583
Queensland, Australia.                            pgp key id: 0x900E515F



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to