Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

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


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


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


What am I doing wrong?

Thanks for the help
Old 07-21-2005, 01:07 PM   #2
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.
# 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, 11:21 AM   #3
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.


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 01:56 PM
will this script copy only certain files? verbatim Programming 5 04-28-2005 09:28 AM
Foreach script to copy files gone wrong... clue? xiaodown Programming 2 11-02-2004 11:00 PM
How to copy in a script files to a samba folder? Julianus Linux - Networking 1 10-09-2004 07:29 PM
Simple Script Files jcai Linux - General 4 09-19-2004 07:15 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:47 PM.

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