[olug] Script help

Edward Pluta epluta3 at cox.net
Sun Dec 28 23:58:46 UTC 2008


You can also use the reverse quotes ` to execute the command. Like this

DIRNAME=backup_`date +%Y-%m%d`

to yield the same results as in the example below. This method also works 
for ksh and csh.

----- Original Message ----- 
From: "Kevin" <sharpestmarble at gmail.com>
To: "Omaha Linux User Group" <olug at olug.org>
Sent: Sunday, December 28, 2008 5:38 PM
Subject: Re: [olug] Script help


> First thing I see wrong, that correcting will result in a different
> error message: There are spaces surrounding your equals sign. Remove
> them and it will result in assigning to DIRNAME the following:
> "backup_", sans quotes. This assumes that date is an empty variable.
> You will also need to tell bash to run the date command by placing
> them in parenthesis.
>
> DIRNAME="backup_$(date +%Y-%m%d)" to give "backup_2008-1228", sans quotes.
> or
> DIRNAME="backup_$(date +%F)" to give "backup_2008-12-28", also sans 
> quotes.
>
>
> On Sun, Dec 28, 2008 at 17:22, Craig Wolf <cjwolf at mpsomaha.org> wrote:
>> I am trying to learn how to write scripts.  My first one is a simple 
>> backup script BUT I am having problems with assigning  data to a 
>> variable: DIRNAME.
>> See following:
>>
>> # 12/28/2008
>> DIRNAME = 'backup_'$date +%Y-%m%d
>>
>> # Create directory on external drive
>> echo "md /usr/backups-data/$DIRNAME"
>>
>> # Backup home directory to external drive
>> echo "cp -Rp /home/* /usr/backups-data/$DIRNAME/home/"
>>
>> # Backup the config files for the system
>> echo "cp -Rp /etc/samba/* /usr/backups-data/$DIRNAME/samba/"
>> echo "cp -Rp /etc/quagga/* /usr/backups-data/$DIRNAME/quagga/"
>> echo "cp -Rp /etc/apache2/* /usr/backups-data/$DIRNAME/apache2/"
>> echo "cp -p /etc/ntp.conf /usr/backups-data/$DIRNAME/"
>> echo "cp -p /etc/dhcpd.conf /usr/backups-data/$DIRNAME/"
>> echo "cp -p /etc/fstab /usr/backups-data/$DIRNAME/"
>>
>> # Backup the web server files (redirection)
>> echo "cp -Rp /srv/www/htdocs/* /usr/backups-data/$DIRNAME/htdocs"
>> echo "cp -Rp /srv/www/alumni/* /usr/backups-data/$DIRNAME/alumni"
>>
>> What am I doing wrong??
>>
>> TIA!
>>
>> Craig Wolf
>> Linux Web Server Support
>> Desktop/Network Specialist
>> 402-715-6283
>> _______________________________________________
>> OLUG mailing list
>> OLUG at olug.org
>> https://lists.olug.org/mailman/listinfo/olug
>>
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> https://lists.olug.org/mailman/listinfo/olug
> 




More information about the OLUG mailing list