Cshell Mutt send Email with String - shell

I am using a .csh script on my Centos 5.5 - yes:) - with Mutt (V 1.5).
Well, I can send an Email no problem like so:
echo "" | mutt -s 'Subject' -i /tmp/body.txt 'test#test.com'
Now I want to save above parameters in a variable and then call mutt with its contents...
The variable contains the following in the end:
-s 'Subject' -i /tmp/body.txt 'test#test.com'
The question is not how to "extract" this string to execute the above command.
I have tried:
set MailString="-s 'Subject' -i /tmp/body.txt 'test#test.com'"
# (Tried these, don't work)
#echo "" | mutt `echo "$MailString"`
#echo "" | mutt `echo $MailString`
#echo "" | mutt echo $MailString`
#echo "" | mutt $MailString`

csh
hope this will help:
#!/bin/csh -f
set MailString="-s 'Subject' -i /tmp/body.txt test#test.com"
mutt ${MailString}
write MailString in ${} and it should work for you
if you would like to have it more flexible:
you can use args for the different fields :
#!/bin/csh -f
set attach_file='file.txt'
set subject='My subject'
set text_file='/tmp/body.txt'
set MailString="-a ${attach_file} -s ${subject} -i ${text_file} test#test.com"
mutt ${MailString}
you can push script's args to different field using $1,$2, etc...

Related

How to pass variable to exec command in expect script?

The purpose of the script is to read an encrypted file ".pass" and decrypt the file using a PublicKey, and the decrypted output should be saved
puts $output
should show the decrypted password.
PublicKey will change every time based on my key generation logic, so I wanted it to be set as a variable
#!/usr/bin/expect
set value "PublicKey"
set output [ exec sh -c {cat .pass | cut -d'&' -f1 | openssl base64 -d | openssl enc -d -rc2 -k "$value" } ]
puts $output
Tcl {braces} are like shell 'single quotes' -- no variable expansion is performed within.
You need to use different quoting:
set value "PublicKey"
set cmd "cat .pass | cut -d'&' -f1 | openssl base64 -d | openssl enc -d -rc2 -k $value"
set output [ exec sh -c $cmd ]
puts $output
There are typographic quotation marks in your file - you need to instead use only ' and " (straight quotation marks) to quote strings.

How to use echo inside another echo [duplicate]

This question already has answers here:
How to pipe multiple commands into a single command in the shell? (sh, bash, ...)
(3 answers)
Closed 4 years ago.
I wish to use an echo command into my bash script.
Actually I do that way =>
echo --- REPORT ---
echo - Report send # $(date +%d-%m-%y_%H:%M)
echo "echo \"Subject: BACKUP-$serv\"" | cat $cheminlogs/backup-$serv.log | /opt/zimbra/postfix/sbin/sendmail -r $mail1 $mail2;
echo - Report done # $(date +%d-%m-%y_%H:%M)
But that's don't work when I call my sh file, that's print the echo linke but won't send me the email into the 3rd line command
If I use my command alone that's ok
echo "Subject: BACKUP-$serv" | cat $cheminlogs/backup-$serv.log | /opt/zimbra/postfix/sbin/sendmail -r $mail1 $mail2;
I don't know how to use the echo in the start of a new command
Perhaps I can change my email command by invertion argument but that's send me an email without textarea cat
cat $cheminlogs/backup-$serv.log | echo "Subject: BACKUP-$serv" | /opt/zimbra/postfix/sbin/sendmail -r $mail1 $mail2;
The form you are looking for is
printf 'Subject: %s\n\n' "$subject" | cat - "$server_log" | sendmail
The - means 'read from standard input'. Note that sendmail will expect an empty line between the header and the message body.

sending multiple files as attachment in e-mail using mailx

I have a requiremnet to send multiple files as e-mail attachmnet in shell script. I have used below command.
(printf "%s\n" "BODY"; uuencode out.txt out.txt ; uuencode asgda.txt asgda.txt ) | mailx -m -s "TEST" emailid#domain.com
However the number of files i want to send as an attachmnet are dynamic. So I want to assign the uuencode ... comand to a variable and then use it. I have tried below way,
$ ATTACH_CMD=$(echo `cat $OUTPUT_FILE`)
$ echo $ATTACH_CMD
uuencode out.txt out.txt ; uuencode asgda.txt asgda.txt
$ (printf "%s\n" "BODY"; $ATTACH_CMD ) | mailx -m -s "TEST" emailid#domain.com
And i am getting below error.
sh: uuencode out.txt out.txt ; uuencode asgda.txt asgda.txt: not found.
Can any one please help me with this? Thanks in advance.
Have you tried using the below code? Not sure why it works, but maybe the below code could be used as a workaround
(printf "%s\n" "BODY"; `echo $ATTACH_CMD` ) | mailx -m -s "TEST" emailid#domain.com`?
For $ATTACH_CMD I have used echo command.
I finally found the way. eval makes the trick
eval $STR
$ ATTACH_CMD=$(echo `cat $OUTPUT_FILE`)
$ echo $ATTACH_CMD
uuencode out.txt out.txt ; uuencode asgda.txt asgda.txt
$ (printf "%s\n" "BODY"; eval $ATTACH_CMD ) | mailx -m -s "TEST" emailid#domain.com

capture SSID in wireshark or tshark

Im new in tshark...below code is a part of a code that captures SSID(NAME of access point) and takes average of its RSSI(power of signal).
I need someone to explane what this line does exactly???
tshark -i prism0 -Y wlan.fc.type_subtype==0x08 -T fields -e wlan.sa -e prism.did.rssi -e wlan_mgt.ssid -a duration:1 > air1.txt
the main code is:
#Main shell script for generating appropriate data for histograms
#$1 (first command line parameter): run length
#$2 (second command line parameter): Target SSID
#Usage: should be run as root, example:
# ./histscan.sh 10 Computer
let i=0;
while [ "$i" -lt "$1" ]; do
let i="$i+1";
tshark -i prism0 -Y wlan.fc.type_subtype==0x08 -T fields -e wlan.sa -e prism.did.rssi -e wlan_mgt.ssid -a duration:1 > air1.txt
echo "SSID AVG-RSSI" > mean.old
RSSI=$(cat air1.txt | grep $2 | cut -f2 | ./rssiMean.sh | cut -d'.' -f1)
if [ -z "$RSSI" ]; then let RSSI=-100; fi
let RSSI="$RSSI+100";
echo $2 " " $RSSI >> mean.old
cp mean.old mean.rssi
done
The tshark command you included here will set up and start a packet capture. Here are the parameters the line specifies.
-i prism => indicates that the capture should be done on the interface named prism0
-Y wlan.fc.type_subtype==0x08 => specifies a display filter. So, this capture will only print out 802.11 frames that are access point beacons.
-T fields => The output will contain just the data fields you specify with all of the -e options
-e => The specific fields to print out. In your case, it will be the WLAN source address [basically the MAC of the access point that sent the beacon], the RSSI, and SSID fields.
-a duration:1 => The capture will run for 1 second
air.txt => Output of the tshark command will be directed to this file.

Sending simple message body + file attachment using Linux Mailx [duplicate]

This question already has answers here:
How to attach a file using mail command on Linux? [duplicate]
(13 answers)
Closed 5 years ago.
I am writing a shell script to send an email using Linux Mailx, the email must contain a file attachment and a message body.
Currently sending an email with an attachment:
output.txt | mail -s "Daily Monitoring" james#dell.com
I wish to add a message body. How should i?
Linux Mailx:
mail [-eIinv] [-a header] [-b addr] [-c addr] [-s subj] to-addr
The usual way is to use uuencode for the attachments and echo for the body:
(uuencode output.txt output.txt; echo "Body of text") | mailx -s 'Subject' user#domain.com
For Solaris and AIX, you may need to put the echo statement first:
(echo "Body of text"; uuencode output.txt output.txt) | mailx -s 'Subject' user#domain.com
The best way is to use mpack!
mpack -s "Subject" -d "./body.txt" "././image.png" mailadress
mpack - subject - body - attachment - mailadress
Johnsyweb's answer didn't work for me, but it works for me with Mutt:
echo "Message body" | mutt -s "Message subject" -a myfile.txt recipient#domain.com
Try this it works for me:
(echo "Hello XYX" ; uuencode /export/home/TOTAL_SI_COUNT_10042016.csv TOTAL_SI_COUNT_10042016.csv ) | mailx -s 'Script test' abc#xde.com
On RHEL Linux, I had trouble getting my message in the body of the email instead of as an attachment . Using od -cx, I found that the body of my email contained several /r. I used a perl script to strip the /r, and the message was correctly inserted into the body of the email.
mailx -s "subject text" me#yahoo.com < 'body.txt'
The text file body.txt contained the char \r, so I used perl to strip \r.
cat body.txt | perl success.pl > body2.txt
mailx -s "subject text" me#yahoo.com < 'body2.txt'
This is success.pl
while (<STDIN>) {
my $currLine = $_;
s?\r??g;
print
}
;
You can try this:
(cat ./body.txt)|mailx -s "subject text" -a "attchement file" receiver#domain.com

Resources