PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Problem with IF statement
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Problem with IF statement

Réponse
 
LinkBack Outils de la discussion
Vieux 06/11/2006, 09h19   #1
Colin Copland
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Problem with IF statement

I have a script I have written to backup a simple fileserver but am
having problems with the if statement in it.

No matter the date a full backup is run. What I wish to happen is a
full backup to be run on a Fri and all other days a incremental one
should run.

Does anyone see any apparent errors in the script?

Thanks,
Colin

=========================================== Backup Script ========

#!/bin/bash

# Set dates

bdate='date +%a%m%Y'
mdate=`date +%d%m%Y`

if

# Check whether full or inc backup is required

${bdate}="Fri%m%Y"

then

#---------------------
# Full Backup
#---------------------

# Remove old backup files older than 30 days

PATHTOCLEAN="/var/backup"
DAYSOLD="30"
find $PATHTOCLEAN -mtime +$DAYSOLD -exec rm {} \;

# Backup /home directories to /var/backup

tar -czf /var/backup/backup-${mdate}-full.tar.gz /home/colin /home/sarah

# Burn backup file to DVD

# Erase dvd in drive
dvd+rw-format -force /dev/hdc

# Create the ISO image
mkisofs -r -o /tmp/backup.iso /var/backup/backup-${mdate}-full.tar.gz

# Write the ISO onto the DVD
growisofs -Z /dev/hdc=/tmp/backup.iso

else

#---------------------
# Incremental Backup
#---------------------

# Remove old backup files older than 30 days

PATHTOCLEAN="/var/backup"
DAYSOLD="30"
find $PATHTOCLEAN -mtime +$DAYSOLD -exec rm {} \;

# Backup /home directories to /var/backup

find /home/colin /home/sarah -mtime -1 -type f -print | tar zcvf
/var/backup/backup-${mdate}-inc.tar.gz -T -

fi

--
GNU/Linux
09:14:01 up 1:10, 1 user, load average: 0.62, 0.43, 0.40
  Réponse avec citation
Vieux 06/11/2006, 10h57   #2
Janis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem with IF statement

Colin Copland wrote:
>
> I have a script I have written to backup a simple fileserver but am
> having problems with the if statement in it.
>
> No matter the date a full backup is run. What I wish to happen is a
> full backup to be run on a Fri and all other days a incremental one
> should run.
>
> Does anyone see any apparent errors in the script?
>
> Thanks,
> Colin
>
> =========================================== Backup Script ========
>
> #!/bin/bash
>
> # Set dates
>
> bdate='date +%a%m%Y'
> mdate=`date +%d%m%Y`
>
> if
>
> # Check whether full or inc backup is required
>
> ${bdate}="Fri%m%Y"


What is this supposed to do.

That's no condition as you might expect. First of all you need some
test operator to embed your condition, either if [ ... ] or if [[
.... ]]
Read any manual to learn about basic shell syntax.

Then, I guess, you'd rather want to dynamically interrogate the current
date, instead of comparing against a string. The output of the date
command as a value can be embedded in your program like $(date ...)

Read also about how to use the different quotes "...", '...', and
`...`.

You might want something like...

case $(date +%d%m%Y) in
Fri*) : whatever to do on Friday
;;
*) : whatever to do on other days
;;
esac

(Even a simpler date format would do the job if you just compare the
week day, BTW.)

[skipping the rest of your program]

Janis

>
> then
>
> #---------------------
> # Full Backup
> #---------------------
>
> # Remove old backup files older than 30 days
>
> PATHTOCLEAN="/var/backup"
> DAYSOLD="30"
> find $PATHTOCLEAN -mtime +$DAYSOLD -exec rm {} \;
>
> # Backup /home directories to /var/backup
>
> tar -czf /var/backup/backup-${mdate}-full.tar.gz /home/colin /home/sarah
>
> # Burn backup file to DVD
>
> # Erase dvd in drive
> dvd+rw-format -force /dev/hdc
>
> # Create the ISO image
> mkisofs -r -o /tmp/backup.iso /var/backup/backup-${mdate}-full.tar.gz
>
> # Write the ISO onto the DVD
> growisofs -Z /dev/hdc=/tmp/backup.iso
>
> else
>
> #---------------------
> # Incremental Backup
> #---------------------
>
> # Remove old backup files older than 30 days
>
> PATHTOCLEAN="/var/backup"
> DAYSOLD="30"
> find $PATHTOCLEAN -mtime +$DAYSOLD -exec rm {} \;
>
> # Backup /home directories to /var/backup
>
> find /home/colin /home/sarah -mtime -1 -type f -print | tar zcvf
> /var/backup/backup-${mdate}-inc.tar.gz -T -
>
> fi
>
> --
> GNU/Linux
> 09:14:01 up 1:10, 1 user, load average: 0.62, 0.43, 0.40


  Réponse avec citation
Vieux 06/11/2006, 16h58   #3
Adam Price
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem with IF statement

On Mon, 06 Nov 2006 09:19:37 +0000, Colin Copland wrote:

> I have a script I have written to backup a simple fileserver but am
> having problems with the if statement in it.
>
> No matter the date a full backup is run. What I wish to happen is a
> full backup to be run on a Fri and all other days a incremental one
> should run.
>
> Does anyone see any apparent errors in the script?
>
> Thanks,
> Colin
>
> =========================================== Backup Script ========
>
> #!/bin/bash
>
> # Set dates
>
> bdate='date +%a%m%Y'

Did you want ` here instead of '?

Adam
  Réponse avec citation
Vieux 08/11/2006, 13h27   #4
Colin Copland
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem with IF statement

Adam Price wrote:
>> #!/bin/bash
>>
>> # Set dates
>>
>> bdate='date +%a%m%Y'

> Did you want ` here instead of '?


Thanks that was the problem. Changed the quotes to ` and runs fine.

Regards,
Colin
--
Colin Copland, Mutleyshome IT Computing
** Web: http://www.mutleyshome.co.uk **
Tel: 0800 066 4767 | Fax: 0870 068 4767
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h50.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,42992 seconds with 12 queries