Postfix transport - invoke script after receive mail [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Debian Sid, latest postfix from Sid.
I need to invoke bash script after user reveive mail. So, what I did:
create file /etc/postfix/transport, for example:
mail#domain.com myscript
run command to create database: postmap transport
add to main.cf: transport_maps = hash:/etc/postfix/transport
add to master.cf: myscript unix - n n - - pipe user=michal flags=FR argv=/home/michal/test.sh
reload postfix
What's the problem? If I configure it this way, after mail is received, script "test.sh" will be executed, but incoming mail will not be delivered to mailbox and it will be deleted immediatelly after receiving.
So - how to avoid this? I need the script to be executed, but incoming mail should be also delivered to my mailbox.

Use Procmail.
:0c
| $HOME/test.sh
The script receives the full message on standard input, but if you don't feel like parsing the message yourself, there are standard techniques for extracting header values into Procmail variables. You can pipe to formail:
SUBJECT=`formail -zcxSubject:`
or you can grab into MATCH, which avoids spawning an external process, but is a bit trickier for more-complex tasks;
:0
* ^Subject:[ ]*\/.+
{ SUBJECT=$MATCH }
(the whitespace inside [ ] should be a space and a tab); either way, you can now pass in $SUBJECT as a parameter on the test.sh command line. Obviously, other header values can be extracted into variables in a similar way.
PS. You cannot inline the formail call like this because it will consume the standard input from the pipe.
:0c
| $HOME/test.sh "`formail -zcxSubject:`" # erroneous!
Instead, you need to split it up, like this:
:0
* ^Subject:[ ]*\/.+
{ SUBJECT=$MATCH }
:0c
| $HOME/test.sh "$SUBJECT"

Related

How to use cURL to verify a web page is fully loaded? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have a case where after deploying to a server, the UI of my web page takes around 20 mins to load. The API is available almost immediately.
I need a way to use curl to load a web page and verify from the response that whether the web page is loaded or not.
Combining curl with grep you can request your page and see if it loads by looking for a specific string you'd expect to see when it renders correctly.
Something like:
curl -o - https://www.example.com/ | grep "Something from successful response"
if [ $? -eq 0 ] ; then
echo "Success"
else
echo "Fail"
fi
The -o - option to curl outputs the response to stdout which is then piped to grep which looks for a specific string from a successful. Depending on your needs there may be other ways but this sounds like it matches what you're asking.
Also note if your UI takes 20 minutes to load the first time, you might need to adjust some curl options (e.g. --max-time) to allow for longer timeouts.

Bash mail script which asks recipient, subject and body [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a problem trying to make my own bash mail script which every time will ask to enter a recipient, subject and body in console. And then send it. Could anyone help with this? Thanks a LOT!
P.S I am using mail command
read -p "What is your subject ? " subj
read -p "What is your message? " mess
read -p "What is the recipient address? " add
grep -E '[[:alnum:]]+#[[:alnum:]]+(.[[:alnum:]]+){1,2}' <<< $add
if [[ "$?" == "0" ]
then
echo "$mess" | mail -s "$subj" $add
else
echo "ERROR - The recipient address is in the wrong format"
fi
Here we read in responses for subject, body and recipient we then check for the correct format of the email address and use the variables to send a mail if the recipient address is in the correct format. If not, show an error message.
You will use the read command to get user input. Hint: use the -p option.
Don't forget to "quote" all your variables, especially with variables holding unknown user input.

search for pattern and remove all lines [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have system logs where alarms are written. in my case i have lots of repeated alarms which i want to ignore and focus only on new alarms that might be exist.
sample alarm :
kbl1infn8:CCC_USER_2049.0002:2016/09/20-17:00:03.560451-00540-03276-CCC_USER_2049- <0N CpocsSs7CircuitCat#040200000000009a|6501646464644309|6501646464c90000-6503010117c80000-1.0.3|a40200003e3d8fd5|0000000e|0000000000000000
kbl1infn8:CCC_USER_2049.0002:2016/09/20-17:00:03.560451-00540-03276-CCC_USER_2049- |RC USSDString=*1234*#|MSISDN=93707678224|
kbl1infn8:CCC_USER_2049.0002:2016/09/20-17:00:03.560451-00540-03276-CCC_USER_2049- |NF NOT: src=ERROR_APPLICATION sev=SEVERITY_MAJOR id=010117c800000001
kbl1infn8:CCC_USER_2049.0002:2016/09/20-17:00:03.560451-00540-03276-CCC_USER_2049- de.siemens.advantage.in.featureframework.FeatureException: GenAcc> [0]theGenericAccess: No value available for SubsDMDB.Subscriber.LanguageID and type INTEGER
kbl1infn8:CCC_USER_2049.0002:2016/09/20-17:00:03.560451-00540-03276-CCC_USER_2049- at de.siemens.advantage.in.features.genericAccess.impl.DynamicAsciiBuffer$Handle.throwNotAvailableException(DynamicAsciiBuffer.java:1105)
--
kbl1infn4:CCC_USER_1025.0009:2016/09/20-00:23:03.981403-25661-28403-CCC_USER_1025- <0N CpocsSs7CircuitCat#020200000000008a|6501646464644309|6501646464c90000-6501646464640000-1.1.1|a20200003cc
31dd2|0000000e|0000000000000000
kbl1infn4:CCC_USER_1025.0009:2016/09/20-00:23:03.981403-25661-28403-CCC_USER_1025- |RC CdPA=173|CgPA=93705040139|
kbl1infn4:CCC_USER_1025.0009:2016/09/20-00:23:03.981403-25661-28403-CCC_USER_1025- |NF NOT: src=ERROR_APPLICATION sev=SEVERITY_MAJOR id=6503010103c80016
kbl1infn4:CCC_USER_1025.0009:2016/09/20-00:23:03.981403-25661-28403-CCC_USER_1025- Exception in flexible core (e.g. during logic execution):de.siemens.advantage.in.featureframework.FeatureExc
eption: Call.checkIfCcOperationIsAllowed(): operation Call.playAnnouncement() only allowed within an open call control dialog
kbl1infn4:CCC_USER_1025.0009:2016/09/20-00:23:03.981403-25661-28403-CCC_USER_1025- at de.siemens.advantage.in.features.flexDTMF.actions.dtmfActions.impl.DTMFActionsController.playAnnounc
ementList(DTMFActionsController.java:360)
--
the above lines are related to one alarms. here i want to omit such alarm in my log file.
I have tried using grep -v 'RC USSDString' IN-201609201800.txt | more but this command removes only the line where the searched pattern grep -v 'RC USSDString' IN-201609201800.txt | more does exist, where i want to remove the entire lines of alarm where pattern is found.
Edit:
- I have added one more alarm separated by double dash
Assuming your alarms are multi line and two alarms are separated with each other by --.
awk -v RS="--" '{$1=$1} !/RC USSDString/' alarmfile
If you want to add , multiple string to be excluded from output then:
awk -v RS="--" '{$1=$1} !/string-1/ || !/string-2/' alarmfile
What you have to do :
grep -Ev 'pattern1|pattern2|pattern3' file

Escaping bash variable [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm a bit stuck with this. I'm delaring a variable at the top of my script, then I am creating a file as part of my script:
app="testing"
cat <<EOF >/etc/init.d/test
#!/bin/bash
args="--emperor $APPCONF/test/$APP.ini"
EOF
It doesn't seem to work though, it seems on the $app variable. Must I do something to this variable to get it to display it's value, "testing" inside the file I create?
Use consistent case. variable names are case sensitive.
Let's say you were doing this the Right Way. You'd want to store your data in an array:
args=( --emperor "${appconf}/test/${app}.ini" )
and then convert it to a string for embedding:
printf -v args_str '%q ' "${args[#]}"`
...and use that string inside your heredoc:
#!/bin/bash
args=( $args_str )
EOF
...beyond which, anything inside the script being created would want to expand it as an array:
run_something "${args[#]}"
See BashFAQ #50 for rationale and details.
Besides using consistent case ($app is different from $APP), you may want to enclose your variable names within brackets - you may get issues if you use spaces in between your variables values otherwise, and it's considered a good practice. For example:
args="--emperor ${APPCONF}/test/${APP}.ini"
That way, $APPCONF does not get confused with ${APP}CONF also. I hope this helps!
I'm not sure to understand your question. I suppose that you would like to end with a file
/etc/init.d/test
containing the text:
#!/bin/bash
args="--emperor $APPCONF/test/testing.ini"
if so your script should be:
app="testing"
cat <<EOF >/etc/init.d/test
#!/bin/bash
args="--emperor \$APPCONF/test/$app.ini"
EOF

How to change sender name (not email address) when using the linux mail command for autosending mail? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
Mailbox shows the sender name as "Apache", because the mail I am autosending is being sent from a Perl CGI program. How do I change it to something else?
You just need to add a From: header. By default there is none.
echo "Test" | mail -a "From: Someone <someone#example.com>" other#example.com
You can add any custom headers using -a:
echo "Test" | mail -a "From: Someone <someone#example.com>" \
-a "Subject: This is a test" \
-a "X-Custom-Header: yes" other#example.com
mail -s "$(echo -e "This is the subject\nFrom: Paula <johny#paula.com>\n
Reply-to: 1232564#yourserver.com\nContent-Type: text/html\n")"
milas.josh#gmail.com < htmlFileMessage.txt
the above is my solution..just replace the "Paula" with any name you want e.g Johny Bravo..any extra headers can be added just after the from and before the reply to...just make sure you know your headers syntax before adding them....this worked perfectly for me.
You can use the "-r" option to set the sender address:
mail -r me#example.com -s ...
In case you also want to include your real name in the from-field, you can use the following format
mail -r "me#example.com (My Name)" -s "My Subject" ...
If no From: header is specified in the e-mail headers, the MTA uses the full name of the current user, in this case "Apache". You can edit full user names in /etc/passwd
It depends on what sender address you are talking about. The sender address visble in the recipients mailprogramm is extracted from the "From:" Header. which can probably easily be set from your program.
If you are talking about the SMTP envelope sender address, you can pass the -f argument to the sendmail binary. Depending on the server configuration you may not be allowed to do that with the apache user.
from the sendmail manpage :
-f <address>
This option sets the address of the envelope sender of a
locally-generated message (also known as the return path).
The option can normally be used only by a trusted user, but
untrusted_set_sender can be set to allow untrusted users to
use it. [...]
On Ubuntu 14.04 none of these suggestions worked. Postfix would override with the logged in system user as the sender. What worked was the following solution listed at this link --> Change outgoing mail address from root#servername - rackspace sendgrid postfix
STEPS:
1) Make sure this is set in /etc/postfix/main.cf:
smtp_generic_maps = hash:/etc/postfix/generic
2) echo 'www-data yourusername#yourdomain.com' >> /etc/postfix/generic
3) sudo postmap /etc/postfix/generic
4) sudo service postfix restart

Resources