LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-21-2005, 10:09 AM   #1
ElricM
LQ Newbie
 
Registered: Jul 2005
Posts: 5

Rep: Reputation: 0
Simple script to copy files, getting \r's at end of cmd


Hello,

I made a simple script (first one) to copy the mysql backups to a subdirectory and append the day. My desire to to have a copy for each day of the week, each week so I can go back to one if there's trouble.

the script (portion) looks like this:

# Set the DAY variable
DAY=`date +%a`
cp mysql.sql daily_copies/mysql.sql.$DAY

However the resulting filename in the subdirectory daily_copies endds up getting two carriage returns added so that the filename ends up as

"mysql.sql.Wed\r\r"

Even if I take the $DAY variable off the filename and just do the copy, the resulting filename is

"mysql.sql\r\r"

What am I doing wrong?

Thanks for the help
 
Old 07-21-2005, 02:07 PM   #2
hlyrad
Member
 
Registered: Jul 2005
Location: Ab Ca
Distribution: Redhat EL Sun Mac OSX FC 3.0 & 4.0
Posts: 44

Rep: Reputation: 15
I don't know why you are getting this error. I cannot reproduce it, however using perl you can remove the newline/carraige return eg.
#!/usr/bin/perl
# Set the DAY variable
$day = `date +%a`;
chomp($day); #Remove new line characters
`cp mysql.sql daily_copies/mysql.sql.$day`; #calls sh to run command
 
Old 07-23-2005, 12:21 PM   #3
ElricM
LQ Newbie
 
Registered: Jul 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the reponse. Turns out that because I used the Java text editor from Webmin, I had a ^M at the end of every line. So the copy command was actually:

cp mysql.sql daily_copies/mysql.sql.$DAY^M

I (re)edited the file using vi in PuTTY and removed them, now it works fine.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need script to copy all files containing a certain string to a directory dc6463 Programming 21 04-18-2013 02:56 PM
will this script copy only certain files? verbatim Programming 5 04-28-2005 10:28 AM
Foreach script to copy files gone wrong... clue? xiaodown Programming 2 11-03-2004 12:00 AM
How to copy in a script files to a samba folder? Julianus Linux - Networking 1 10-09-2004 08:29 PM
Simple Script Files jcai Linux - General 4 09-19-2004 08:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration