error in sh script while copy files to a backup directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting error in sh script while copy files to a backup directory
# 1  
Old 09-30-2010
error in sh script while copy files to a backup directory

I am trying to copy files from one directory to another using shell script. Can anyone please troubleshoot the code.

thanks in advance...


Code:
 
#!C:\Shell\sh.exe
files_dir="C:\Documents and Settings\scripts\files"
backup_dir="C:\Documents and Settings\scripts\ztest"
 
echo cding to files directory
cd $files_dir
 
echo copying all files to backup directory
copy $files_dir $backup_dir
 
 
 
Output:
 
C:\Documents and Settings\scripts>sh backup.sh
cding to files directory
cd: can't cd to C:\Documents
copying all files to backup directory
copy: not found

# 2  
Old 09-30-2010
I see you're using Windows, which might make things quite different than a usual Linux or UNIX shell script, but for starters, try:

Code:
cd "${files_dir}"

Since the directory had spaces it was splitting it into parts, quotes stop that.

I believe COPY is built into windows cmd.exe now, you may need to install cp to get a commandline utility for that which works in your shell.
# 3  
Old 10-01-2010
As Corona688's suggestion, you need quote all the vars.
Code:
cd "$files_dir"

copy "$files_dir" "$backup_dir"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

How to backup a directory (sub-directories/files) files from one server on to other ?

Hello, Server A: /directory1/ Server B: /Backups/ i wanted to backup contents of /directory1 from "server A" on to "Server B" every 1 hour. If there is any change in (only new/differences) contents on serverA (directory1/) supposed to be backeup on next run. I did used rsync command to... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. Shell Programming and Scripting

Bash script to copy apache log files to client directory

Our Apache log files are written to a location on the server that we as clients have no access. Don't ask. Every month, I have to e-mail the administrator to have him manually copy our Apache log files to a directory in our file space. You can probably guess how efficient it is to do things this... (3 Replies)
Discussion started by: gregraven
3 Replies

3. Shell Programming and Scripting

Error on script to copy files

Hi I have the following script to copy files from one directory to another: #!/bin/sh touch -mt 201304240000 /var/tmp/ref1 touch -mt 201305152359 /var/tmp/ref2 find /moneta_collected02/in_psl -type f \( -newer /var/tmp/ref1 -a ! -newer /var/tmp/ref2 \) > file_lst cp -pr $(< file_lst)... (6 Replies)
Discussion started by: fretagi
6 Replies

4. Shell Programming and Scripting

Copy the files in directory and sub folders as it is to another directory.

How to copy files from one directory to another directory with the subfolders copied. If i have folder1/sub1/sub2/* it needs to copy files to folder2/sub1/sub2/*. I do not want to create sub folders in folder2. Can copy command create them automatically? I tried cp -a and cp -R but did... (4 Replies)
Discussion started by: santosh2626
4 Replies

5. Shell Programming and Scripting

Need a shell script which takes two inputs and copy the files from one directory to other

Hi, I am using solari 10 OS which is having bash shell. I need a shell script which takes user home directory and name of the file or directory as a input and based on that copy the files accordingly to the other directory. example:I hava a machine1 which is having some files in a... (8 Replies)
Discussion started by: muraliinfy04
8 Replies

6. Shell Programming and Scripting

Find all .htaccess files and make a backup copy in respective directories

Hey guys, I need to know how to locate all .htaccess files on the server and make a backup of them in the folder they reside before I run a script to modify all of them. So basically taking dir1/.htaccess and copying it as dir1/.htaccess_bk dir2/.htaccess copying as dir2/.htaccess_bk... (5 Replies)
Discussion started by: boxx
5 Replies

7. Shell Programming and Scripting

Script to Poll Directory and Copy files

Hi all, I'm looking for a script to poll a specified directory and copy new files to another location. The script should only copy new files so, I based on mtime I guess? Can anyone point me in the right direction of a script which could do this? My scripting skills aren't too bad, but... (1 Reply)
Discussion started by: JayC89
1 Replies

8. Shell Programming and Scripting

Help: Bash backup script (includes copy, test-

Basically it's for a work assignment. Have to make a menu with the following choices ***************menu********************* 1) Show Current Directory 2) Dispaly Current Time and Date 3) Copy 4) Change Password 5) write directory to file 6) Edit File Directory 7) Make backup from... (1 Reply)
Discussion started by: Covax
1 Replies

9. Shell Programming and Scripting

Copy files gives "cp: omitting directory" error

I tried to copy data from one location to multiple location my typing... cp <source> <dest> <dest> however this will omits one of the destination ... and proceed to copy to only one directory (2 Replies)
Discussion started by: dplate07
2 Replies

10. Shell Programming and Scripting

shell script to find and copy the files creted in the year 2006 to another directory

Hi All, I am new to UNIX. I will be thankful if some one helps me. I have to write a shell script for one of the requirement. I have files created from Jan 2006 to March 2008. My requirement is to write a script in such a way that 1) To find and copy(not Moving) the files created in the... (2 Replies)
Discussion started by: manas6
2 Replies
Login or Register to Ask a Question