The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script to search for text in a file and copy file imeadows UNIX for Dummies Questions & Answers 9 11-12-2008 09:12 PM
Copy text from a file from VI editor to Windows clipboard zhshqzyc UNIX for Dummies Questions & Answers 13 08-07-2007 07:19 PM
I want to copy the text output from a 'nohup.out' file. Iamthe great UNIX for Dummies Questions & Answers 3 05-01-2007 01:41 PM
appending string to text file based on search string malaymaru Shell Programming and Scripting 1 06-09-2006 09:53 AM
find and copy string in a file vascobrito UNIX for Advanced & Expert Users 10 03-03-2004 02:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-02-2008
hpuxlxboy hpuxlxboy is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
Post How to copy a string to a text file

I am using the following command to email a tex file as an attachment-

cat mailtext.txt | elm -s "Subject" emailAddr
where content of mailtext.txt is -
"Body of email"
[include foo.txt text/plain base64]

This will attach foo.txt with the email.

My problem is that the file foo.txt is ceated dynamically everytime with a timestamp. e.g. foo_<timestamp>.txt

So if this filename is collected in a variable-
sFileName = foo_<timestamp>.txt

How do I include this filename dynamically in the mailtext.txt file?

Any help would be appreciated.

Thanks.
  #2 (permalink)  
Old 08-03-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Use a HERE document and interpolate the value of a variable containing the file name.


Code:
elm -s "Subject" emailAddr <<HERE
"Body of email"
[include $sFileName text/plain base64]
HERE

With this solution, you don't need the external file at all. (Of course, if you still need an external file for other reasons, you can create it from a HERE document and then simply keep the sending part like you already had it, perhaps modulo the Useless Use of Cat.)
  #3 (permalink)  
Old 08-03-2008
hpuxlxboy hpuxlxboy is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
Thanks for the solution ...

I am providing this command in a C program.

sprintf( cmd, "elm -s SUBJECT %s <<HERE \n %s \n [include %s text/plain base64] \n HERE ", emailAddr, sMailBody, sFileName );

This is sending the [include %s text/plain base64] part also in the email body along with the actual body text. And there is no file attached in the email.

Could you please help me with this ???
  #4 (permalink)  
Old 08-03-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The <<HERE is a feature of the shell; you need to spawn a shell to get it working.


Code:
sprintf (cmd, "sh -c 'elm -s SUBJECT %s <<HERE\n"
  "%s\n[include %s text/plain base64]\nHERE\n'"l, emailAddr, sMailBody, sFileName);

You are not allowed any leading whitespace on the line containing the terminating HERE (at least not in many shells).

Couldn't you just open a pipe to "elm -s SUBJECT %s" with popen() and pipe in the content yourself, though? That's pretty much equivalent to using a HERE document. (And you avoild the pesky security considerations you always bump into when spawning a shell with user-supplied input.)

If the file truly is text/plain, what's the benefit of encoding it in base64, by the way?
  #5 (permalink)  
Old 08-03-2008
hpuxlxboy hpuxlxboy is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
Could you please explain me how to use popen() ?

It could be a pretty simple thing, but I m a novice in unix. It would be good if you could show me the command.
  #6 (permalink)  
Old 08-04-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Googling for "popen examples" gets me e.g. popen
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0