![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Backing up the system | eykyn17 | SUN Solaris | 6 | 03-28-2007 12:49 PM |
| Can usfdump be used for backing up 1 directory? | FredSmith | SUN Solaris | 5 | 01-12-2007 01:31 PM |
| backing up the vtoc | BG_JrAdmin | UNIX for Dummies Questions & Answers | 1 | 12-22-2005 08:33 PM |
| Best practises for backing up | d11wtq | UNIX for Dummies Questions & Answers | 2 | 07-06-2005 09:11 PM |
| backing up | merlin | UNIX for Dummies Questions & Answers | 4 | 09-09-2001 05:35 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Backing Up Directories
Hi Guys,
I'm writing a shell script that presents the user with various options, they select one (numbered 1-9) and it then excecutes the correct code. No problem, but I'm having slight difficulty with one option. The user can select to backup all the files in the current directory to another directory, but the program must first check to see if the destination directory exists and then if not it must create it before copying the files. backup) print "Please enter the directory to copy your files to:" read dir if [ -f $dir ]; then mkdir $dir cp /myhomefolder/* $dir else cp /myhomefolder/* $dir fi;; This is the code I'm using to take the users chosen directory, see if it exists within the current directory and make it if not then copy the files but it's just not working! It just says that the directory entered is not a directory. I'm a bit of a newbie when it comes to this and I've been trawling through websites and books but I just can't get it to work! Any thoughts? Thankx |
|
||||
|
try useing a -d in your if statment. -d= is a directory you might even want to do a -w (you have write premissions) in ksh -f = is a regular file (ie not a directory or other special type of file. i added a -p in your mkdir so it makes any directorys that would be missing in the $dir variable instead of just the last directory. so something liek this: Code:
if [ -d $dir ]; then cp /myhomefolder/* $dir else mkdir -p $dir cp /myhomefolder/* $dir fi;; |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|