Is procmail chrooted or limited in using linux commands? - email

im using procmail to forward emails to different folders in my Maildir.
I use these two lines to get the FROM and TO from the mail, which works pretty fine.
FROM=`formail -x"From:"`
TO=`formail -x"To:"`
These two commands return the whole line without the From: and To: prefix.
So i get something like:
Firstname Lastname <firstname.lastname#mail-domain.com>
Now i want to extract the email between < and >.
For this i pipe the variable FROM and TO grepping it like this.
FROM_PARSED=`echo $FROM | grep -o '[[:alnum:]+\.\_\-]*#[[:alnum:]+\.\_\-]*'`
TO_PARSED=`echo $TO | grep -o '[[:alnum:]+\.\_\-]*#[[:alnum:]+\.\_\-]*'`
But when i print FROM_PARSED into the procmail log by using LOG=FROM_PARSED, i get an empty string in FROM_PARSED and TO_PARSED.
But if i run these commands on my console, all works fine. I tried many other grepping methods, using grep, egrep, sed and even cut (cutting < and >). All working on console, but i use it in procmail it just returns nothing.
Is it possible that procmail is not allowed to use grep and sed commands? Something like a chroot?
I dont get any error logs in my procmail log. I just want to extract the valid email address from the FROM and TO line. Extracting with formail works, but parsing it with grep or sed fails, even if expression is correct.
Could somebody help? Maybe i need to setup procmail somehow.

Strange.
I added this to the users .procmailrc file
SHELL=/bin/bash
The users shell was set to /bin/false, which is correct because its a mail user, no ssh access at all.

You should properly quote "$FROM" and "$TO".
You will also need to prefix grep with LC_ALL=POSIX to ensure [:alnum:] will actually match the 26 well-known characters + 10 digits of the English alphabet.

You already solved this, but to answer your actual question, it is possible to run procmail in a chroot, but this is certainly not done by Procmail itself. Sendmail used to come with something called the Sendmail Restricted Shell (originally called rsh but renamed to remsh) which allowed system administrators to chroot the delivery process. But to summarize, this is a feature of the MTA, not of Procmail.

Related

Is it possible to list all tags across all behat tests?

I have several hundred behat tests created by many people who used different tags. I want to clean this up, and to start with I want to list out all the tags which have been used so far.
I wanted to answer my own question as it was something I could not find an answer to elsewhere.
I tried initially to use a custom formatter but that did not work.
https://gist.github.com/paulmozo/fb23d8fb436700381a06
Eventually I crafted a Bash command to suit my purposes
bin/behat --dry-run 2>&1 | tr ' ' '\n' | grep -w #.* | sort -u
This runs the behat command with --dry-run which does not execute the tests, merely outputs the steps so I can pipe them to another tool. The 2>&1 redirects the standard error to null (this is shell dependent). The tr tool breaks every word in the stream into a separate line. The grep searches for lines starting with the # symbol. Finally sort -u sorts the list and returns the uniques.
This command takes about 15 seconds to run and did the job perfectly for me.

Combining grep and sendmail

I am looking for a way using the command line in UNIX to email the results from a grep command.
I am grepping the error logs looking for a "searchword". I temporarily want to email the results to my work account. This is a temporary solution until the SA has the time to write a script that will write it to a file where the file will be read by an automated analyzing program.
sendmail joetester#workemail.com < grep searchword error*
Does anyone have an idea on how to do it that they can share. Thank you.
You want something like grep searchword error* | sendmail joetester#workemail.com, see this question.

sed command is not working properly

I'm trying to replace the word in shell script with sed -e command but its not replacing , please help on that, i have tried the below
we have separate file in /data/docs/config.log, in that file there is a word ?account for example ,
username acc, passsword acc, ?account.name
this ?account word needs to be replaced with word 'GLOBAL' using sed -e command ,
reacc = GLOBAL
sed -e "s/?account/$reacc/g" /data/docs/config.log > /data/docs/newconfig.log
but here the file newconfig.log has created with 0 size , no output written to the file , its not replacing its an empty file,
the output should be username acc, passsword acc, GLOBAL.name in newconfig.log
Being the only person who can reproduce the problem, you are pretty much on your own. There are plenty of things you can do to analyze the problem, though.
Double-check the shell. Don't have blind faith in #!/bin/sh. In cygwin for example, /bin/sh is an alias for bash. Verify with: echo $SHELL
Check permissions and file system. Do you have rights to write to the output file? Is the disk full? Does cat /data/docs/config.log > /data/docs/newconfig.log work? Test again in a different folder.
Double-check the output file. Is it really empty, or is the file system just slow with updating the file size? Is sed really finished? Test without output redirection; see if the output is dumped to stdout.
Test with a small file; one or two lines is enough.
If even that does not work, then test sed itself. Who knows, maybe you have a weird alias that hides the real sed. The most trivial filter is sed -e '', which should simply echo every line you type (just like cat without parameters). Does that work? Then try some simple patterns.
Systematically iterate between test cases that succeed and test case that fail, until you have found the breaking point. Doing so, you should be able to find the cause. Sorry, that's all I can do for you right now.
Remove spaces around =. Try after making
reacc=GLOBAL

End of script output before headers: hello.pl

Update: 07/12/13
The script works through command line.
"------extra line" is to show an extra return key stroke in editor.
XAMPP: 1.8.2
Server: Apache 2.4
Issue:
I keep receiving the error "End of script output before headers: hello.pl" for a simple hello world perl script. I'm trying to execute the script via a web server "xampp".
Curious Note:
I can use another Perl script which will initially work. However when I make a simple change such as a space, return or comment "#", the script will no longer function. However if I remove the change and save it the script will work again.
Check List
Confirm correct path to perl
Output header (see perl code below)
Extra line at end of script (I heard this could resolve issue)
Confirmed correct privileges in httpd.config
Transferred file via ftp in ASCII
Perl Script:
#!"C:\xampp\perl\bin\perl.exe"
print "Content-Type: text/html\n\n";
print "hello world";
------extra line
httpd.config
<Directory "C:/xampp/htdocs">;
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>;
Maybe your editor changes the line ending characters to windows one.
CGI output needs to be started with HTTP.., two \n then header, then the body between the right HTML codes (Why doesn't my Perl CGI program work on Windows?)
Check the actual chars in a editor that shows you the line endings (like notepad++).
To my best knowledge, the shebang (#!) line is ignored in windows.
The probable cause:
http://perl.baczynski.com/wtf/solved-mystery-perl-on-xampp-wont-run-modified-scripts
tl;dr: turn off your COMODO antivirus, or it's sandbox feature.
Might be a known PHP bug (https://bugs.php.net/bug.php?id=66474). Try different versions of PHP?
Probably this is SELinux blocks.
try this
setsebool -P httpd_enable_cgi 1
chcon -R -t httpd_sys_script_exec_t cgi-bin/your_script.cgi

How can I script the body of a VMS mail?

I have a script that addresses and sends an email but I need a body in the message without creating a file and then inserting the file with the standard MAIL commandline.
How can I do that?
Assuming the body you want to create is something you can write to SYS$OUTPUT (e.g. the output of a command procedure or DCL command), then you can use DCL PIPE to pipe the output into VMS Mail, like:
$ PIPE write sys$output "The date is ", f$cvtime() | MAIL SYS$INPUT smith/SUBJ="Piping in DCL"
or
$ PIPE DIR *.LOG | MAIL SYS$INPUT smith/SUBJ="Piping in DCL"
The PIPE command was added in OpenVMS V7.1. If you are somehow on an pre-7.1 system, then your only choice is writing to a temporary file and cleaning up.
Edit: To answer the comment, if you want to eliminate the interactive displays from the Mail command, you can redirect SYS$OUTPUT to NLA0:, as in:
$ PIPE DIR *.LOG | MAIL SYS$INPUT smith/SUBJ="Piping in DCL" > NLA0:
Error messages go to SYS$ERROR, so you'll still see any failures. See HELP PIPE for more goodness.
Have the script create a temporary file to hold the body of the message.
Mail will accept a text file on the command line, like the list of users and the /subj