Register
It is currently Wed Oct 22, 2014 5:55 pm

Preserving new line characters with backtics


All times are UTC - 6 hours


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 PostPosted: Thu Oct 31, 2013 5:57 pm   

Joined: Thu Oct 31, 2013 5:52 pm
Posts: 5
I am building an email that combines text and the output from command using backtics. I know about the echo -e option and using quotes but that does not help.
Code:
.
.
.
results=`some command`
message="$message\n$results"
.
.
.
echo -e "$message" | mail yada yada

All the new lines that are added when I create message but the new lines from $result are all gone. How do I preserve that formatting? TIA.


Top
 Profile  
 PostPosted: Fri Nov 01, 2013 7:10 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
hi,

I can't reproduce this behaviour.
may be by telling us what `some command` is.


Top
 Profile  
 PostPosted: Sat Nov 02, 2013 7:04 am   

Joined: Thu Oct 31, 2013 5:52 pm
Posts: 5
Thanks for the reply. In this case the command is 'dump'.


Top
 Profile  
 PostPosted: Sat Nov 02, 2013 7:52 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
Unfortunately I don't have this comand on GNU/Debian.
What does it dumps?
Could you redirect its output to file that you'd upload here as an attachment, so it saves its format?


Top
 Profile  
 PostPosted: Sat Nov 09, 2013 5:37 am   

Joined: Thu Oct 31, 2013 5:52 pm
Posts: 5
I hadn't thought of that. I'll give it a try. Thanks.


Top
 Profile  
 PostPosted: Tue Nov 19, 2013 4:44 am   

Joined: Thu Oct 31, 2013 5:52 pm
Posts: 5
No joy. The file itself looks correct:
Code:
cat /tmp/dump.txt
  DUMP: Date of this level 18 dump: Tue Nov 19 05:15:12 2013
  DUMP: Date of last level 17 dump: Mon Nov 18 05:07:29 2013
  DUMP: Dumping /dev/sda1 (/boot) to /stage-backup/inc-11192013/boot001
  DUMP: Label: none
  DUMP: Writing 10 Kilobyte records
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 45 blocks.
  DUMP: Dumping volume 1 on /stage-backup/inc-11192013/boot001
  DUMP: Volume 1 started with block 1 at: Tue Nov 19 05:15:12 2013
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /stage-backup/inc-11192013/boot001
  DUMP: Volume 1 completed at: Tue Nov 19 05:15:12 2013
  DUMP: Volume 1 50 blocks (0.05MB)
  DUMP: 50 blocks (0.05MB) on 1 volume(s)
  DUMP: finished in less than a second
  DUMP: Date of this level 18 dump: Tue Nov 19 05:15:12 2013
  DUMP: Date this dump completed:  Tue Nov 19 05:15:12 2013
  DUMP: Average transfer rate: 0 kB/s
  DUMP: DUMP IS DONE

but when I do:
Code:
results=`cat /tmp/dump.txt`
message="$message\n$results"

the resulting email is exactly the same.
Code:
Starting inc dump on 11/19/13 at 02:00:01.
Estimating size of dump for /root
Estimated size of dump for /root is 29151209472
DUMP: Date of this level 18 dump: Tue Nov 19 02:00:08 2013 DUMP: Date of last level 17 dump: Mon Nov 18 02:00:07 2013 DUMP: Dumping /dev/sda3 (/) to /stage-backup/inc-11192013/root001 DUMP: Label: none DUMP: Writing 10 Kilobyte records DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 28467978 blocks. DUMP: Dumping volume 1 on /stage-backup/inc-11192013/root001 DUMP: Volume 1 started with block 1 at: Tue Nov 19 02:00:13 2013 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: 54.71% done at 51919 kB/s, finished in 0:04 DUMP: Closing /stage-backup/inc-11192013/root001 DUMP: Volume 1 completed at: Tue Nov 19 02:09:28 2013 DUMP: Volume 1 28467830 blocks (27800.62MB) DUMP: Volume 1 took 0:09:15 DUMP: Volume 1 transfer rate: 51293 kB/s DUMP: 28467830 blocks (27800.62MB) on 1 volume(s) DUMP: finished in 555 seconds, throughput 51293 kBytes/sec DUMP: Date of this level 18 dump: Tue Nov 19 02:00:08 2013 DUMP: Date this dump completed: Tue Nov 19 02:09:28 2013 DUMP: Average transfer rate: 51293 kB/s DUMP: DUMP IS DONE
inc backup of /root complete at Tue Nov 19 02:09:29 EST 2013

Note that in the file an 'od' shows each line ending in x'0a'. Also, I doubt it matters but this is CentOS 6.


Top
 Profile  
 PostPosted: Tue Nov 19, 2013 7:25 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
cat alone won't tell much about format, you need to add the -A option.


Top
 Profile  
 PostPosted: Wed Nov 20, 2013 8:29 am   

Joined: Thu Oct 31, 2013 5:52 pm
Posts: 5
Looks good. Shows only '$' at the end of each line.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP