Creating directories based on a day variable

Discussion and support for all Linux distributions and Unix flavours (FreeBSD, OpenBSD, etc).
Post Reply
Kasyx
Registered User
Posts: 139
Joined: 13 Dec 2006, 02:00

Creating directories based on a day variable

Post by Kasyx »

Busy working on a backup script wherein I need to have directories on the backup drive named for the particular day of the backup and have run into a bit of a snag. This is probably because I am an idiot.

Basically, it looks like this:

Code: Select all

DAY=`date +%A`
mkdir /mnt/backup/$DAY
Now, this all seems well in practice, and I can create the directory using that variable manually, however when running the script I get this:

Code: Select all

mkdir: `/mnt/backup/Monday' exists but is not a directory
I'm not really sure where to go from here. Any help would be greatly appreciated.
AlphA
Registered User
Posts: 3213
Joined: 15 Mar 2005, 02:00
Location: JHB
Contact:

Re: Creating directories based on a day variable

Post by AlphA »

howzit,

You probably have a file in /mnt/backup called "Monday"

Code: Select all

#!/bin/ksh
day=`date +%A`
mkdir /absolute_path/$day
I cant test as I am currently doing video encoding in Windows......but I dont see why the above should not work - i just ran it in ksh on AIX.

EDIT : You need to obviously use the bash shell and not ksh if you're working in Linux.
Image
Kasyx
Registered User
Posts: 139
Joined: 13 Dec 2006, 02:00

Re: Creating directories based on a day variable

Post by Kasyx »

Yeah. It turns out that I am an idiot. I wasn't creating an absolute path, thus the directories were appearing in /usr/bin/local from where I was running the script.

Thanks for the help :)
AlphA
Registered User
Posts: 3213
Joined: 15 Mar 2005, 02:00
Location: JHB
Contact:

Re: Creating directories based on a day variable

Post by AlphA »

Cool. Glad you're sorted.
Image
Post Reply