executing/including command in mailx subject line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting executing/including command in mailx subject line
# 1  
Old 04-06-2010
executing/including command in mailx subject line

Hi,
Is it possible for me to include the results from a command in the subject line? What I am looking to do is get the file count and include it into the subject line as well as the list of files in the body.

Example Subject line: Currently 25 files in directory

My Code:
Code:
#!/bin/ksh
cd /opt/app/mydirectory
ls -otrg|awk '{print $4 " " $5 " "$6 " "$7}' | /usr/bin/mailx -s "Currently #want to run ls -l | wc -l here# files in directory" email@email

I am a little new to scripting so I appreciate the help.

I can successfully email me the list of files out, formatted how I need, but would like to include the file count in the subject of the email.

Running on solaris 10.

Thanks,
Ozifer

Last edited by pludi; 04-07-2010 at 02:04 AM..
# 2  
Old 04-06-2010
I have not tried to execute a command within the subject line but often include variables. You can try executing the command using "`" back ticks like;
Code:
ls -otrg|awk '{print $4 " " $5 " "$6 " "$7}' | /usr/bin/mailx -s "`ls -l | wc -l` files in directory" email@email

or if that does not work
Code:
num_files="`ls -l | wc -l`"
ls -otrg|awk '{print $4 " " $5 " "$6 " "$7}' | /usr/bin/mailx -s "Currently $num_files files in directory" email@email

[/code]
# 3  
Old 04-06-2010
or add an attachment
Code:
ls -l /path/to/directory | uuencode listing | mailx -s "file count: $(ls |wc -l)" me@mycompany.com

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Variable not displaying in subject line of mailx email

Hi Newbie here with first post. I've got a shell script (ksh) whereby I run a SQL*Plus script and output the results to a file. I then check the output file in an if statement that looks like this: if ]; then export GAPNUM=`awk '{print $4}' $OUTFILE` if ] then mailx -s... (10 Replies)
Discussion started by: ltzwoman
10 Replies

2. Shell Programming and Scripting

Content of attachment is displaying along with subject in mailx

Hi All, I want to send the csv to an email address. I have tried the below two approaches. Approach1: Got error -ksh: uuencode: not found $ uuencode test_file.csv test_file.csv | mailx -s "Attaching test" msdc.kiran@gmail.com </usr/home/test_file.csv -ksh: uuencode: not found Approach2:... (6 Replies)
Discussion started by: ROCK_PLSQL
6 Replies

3. Shell Programming and Scripting

Executing a command line in a directory and its subdirectories

I'm finally about to make the jump from PHP's mysql driver to the newer mysqli one using the mysqli converter tool. The tool is called by this command line: php /usr/share/nginx/html/rather/converter/cli.php -d -p ".php,.shtml,.inc" -u -b -v -w >> /tmp/convert.log e.g. at the web root:... (2 Replies)
Discussion started by: dheian
2 Replies

4. Shell Programming and Scripting

How to extract the subject from a script which uses mailx

Hi, I need to extract the subject of an e-mail sent using mailx. mailx is in a a file and the command reads like the following Ex: sendMail.sh mailx -s ' This is the subject' $recepiant note that anything can come within ' ' which goes to the subject. Please help (5 Replies)
Discussion started by: mwrg
5 Replies

5. Shell Programming and Scripting

Adding date to the subject using mailx

Hi , I want to add date to the subject of the email. I am using mail and used -s "SQL Loader was not able to load enid on `date` due to data error" But it didnt work. can any one help me ?? Thanks Sithara (1 Reply)
Discussion started by: sithara
1 Replies

6. Shell Programming and Scripting

Mailx: How to send a attachment using mailx command

Hi All, Can anyone please provide the command for sending an mail with attachment using mailx command. Thanks in Advance :) Regards, Siram. (3 Replies)
Discussion started by: Sriram.Vedula53
3 Replies

7. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

8. UNIX for Dummies Questions & Answers

Reading a line including spaces

Hi All, I have a script that reads a file and echo it back to std out. Test.txt 1aaaaaaaaaaa . The script is ReadLine.sh #!/bin/ksh cat $1 | while read file do echo $file done I invoke the script as ReadLine.sh Test.txt The output that I get is (1 Reply)
Discussion started by: aksarben
1 Replies

9. UNIX for Advanced & Expert Users

use email subject line as shell command

If anyone can give me some ideas on this it would be great. What I'm trying to do is to have emails be sent to my unix account. Once they are emailed to the unix account, I want to use the text in the subject field to invoke a shell script, so basically I need to find a way that I can... (4 Replies)
Discussion started by: mskarica
4 Replies

10. Programming

Executing command line options

Can someone please tell me how to modify/add to this code so that it recognizes UNIX command options (all beginning with "-") and executes the command with options? #include<stdio.h> #include<stdlib.h> int main(int argc, char *argv) { int i; system("stty -echo"); ... (8 Replies)
Discussion started by: Safia
8 Replies
Login or Register to Ask a Question