send email from openVMS - email

I am not familiar with OpenVMS but I would like to understand how to write a script that will send an email whenever I call it. My understanding is that the body of the email is put in a temp file before it is converted to text and sent. How do I create this file? Do you have any examples to write a script that will send an email like this?
From: blah#gmail.com
To: you#gmail.com
Subject: this is a body
Body:
Line 1
Line 2
Line 3
Thank you in advance.

$ temp = f$unique() + ".tmp"
$ open/write/error=error temp 'temp'
$ write temp "line1"
$ write temp "line2"
$ write temp "line3"
$ close temp
$ define/user tcpip$smtp_from "blah#gmail.com"
$ mail/subject="this is a body" 'temp' "you#gmail.com"
$ delete/nolog 'temp';*
$ goto exit
$error:
$ write sys$output "Unexpected error: " + f$message ($status)
$ goto exit
$exit:
$ exit

You can send email from the command line:
$ mail/subject="this is a body" Sys$Input you#gmail.com
Line 1
Line 2
Line 3
$ exit
Normally you would create a file to send first:
$ create MyMessage.txt
Line 1
Line 2
Line 3
$ mail/subject="this is a body" MyMessage.txt you#gmail.com
$ delete MyMessage.txt;
Documentation is here.

The answer that I saw includes the files into your body.
You maybe want to join a file... Here's how I attach a file in email:
$ UUENCODE my_file_to_attach.ext my_file_to_attach.ext
$ MAIL/SUBJECT="A subject..." my_file_to_attach.ext you#a_domain.com
$ DELETE my_file_to_attach.ext;
If you want to include a body:
$ CREATE temp.file
Hello,
Here's the in attachment.
Regards.
$ UUENCODE my_file_to_attach.ext my_file_to_attach.ext
$ TYPE my_file_to_attach.ext, temp.file physical_file_send.txt
$ MAIL/SUBJECT="A subject" physical_file_send.txt you#a_domain.com
$ DELETE physical_file_send.txt;, my_file_to_attach.ext;

Related

Running perl files from a text file

There're multiple perl scripts that is ran from CYGWIN terminal. An example is,
$ perl IdGeneratorTool.pl JSmith -i userInfo.adb -o JSmith.txt
The above is an example. Were based on input parameter JSmith, it reads a db file, generate an ID and output that to a text file.
Now these perl scripts running on the CYGWIN keeps growing and it's added to a text file like shown below,
$ perl IdGeneratorTool.pl JSmith -i userInfo.adb -o JSmith.txt
$ perl IdGeneratorTool.pl PTesk -i userInfo.adb -o PTesk.txt
$ perl IdGeneratorTool.pl CMorris -i userInfo.adb -o CMorris.txt
$ perl IdGeneratorTool.pl JLawrence -i userInfo.adb -o JLawrence.txt
$ perl IdGeneratorTool.pl TCruise -i userInfo.adb -o TCruise.txt
...
....
......
.......
.........
And the list keeps growing.
I would like to know whether there's a way to execute all these perl scripts which are in a text file in one go.
I'm new to perl and doesn't have much idea as to what are the options.
An ideal scenario might be, a tool where i can open this text file and click a execute button and then it executes all the scripts and output multiple *.txt files into the same directory.
Or maybe a simple perl script that can do it.
Put them into a file makeall (or whatever you want to call it.
Put as a first line #!/bin/bash into the file
In cygwin enter chmod +x makeall
in cygwin enter ./makeall
With this you've created a bash script which'll do all your calls of the perl script.
Another option would to just put all the user information into a csv file and read that one in order to call your script.
WAIT! Even easier!
Put into the makeall script this:
#!/bin/bash
for user in \
JSmith \
PTesk \
CMorris \
JLawrence \
TCruise \
; do
perl IdGeneratorTool.pl "$user" -i userInfo.adb -o "$user".txt
done
Now you just need to add any additional user the same way I did for your examples.
Without seeing the source for IdGeneratorTool.pl it's hard to give any specific advice; but it is generally not hard to turn something like
do_stuff($ARGV[0], $opt_i, $opt_o);
into
while (<>) {
chomp;
$user, $adb, $outputfile = split('\t');
do_stuff($user, $adb, $outputfile);
}
to read the input from a tab-delimited file instead of from command-line arguments.
You can create text file with list of users (one per line) for example user_list.txt
JSmith
PTesk
CMorris
JLawrence
TCruise
Then create bash script process_list.sh with following content in same directory
#!/bin/bash
for user in `cat user_list.txt`
do
perl IdGeneratorTool.pl $user -i userInfo.adb -o ${user}.txt
done
Now make bash script executable chmod +x process_list.sh and it is ready for execution.
Once you need to add new user edit user_list.txt to add one more line into the file.
Polar Bear

How to add X-header to unix mailx or add attachment to usr/sbin/sendmail

I am attempting to add the x-header X-APP-VOLT: Yes to the header of my email with a .tar attachment. I only have access to usr/sbin/sendmail and mailx. I do not have root access so I can't download other versions of mailx or mutt.
I can add the x-header to usr/sbin/sendmail using the below code, but I can't figure out how to add the .tar attachment.
/usr/sbin/sendmail -i -- toemail << END
To: toemail
Subject: Test
X-APP-VOLT: Yes
Hope this works! END
I can attach a .tar file to mailx using the the below code, but I can't figure out how to add a x-header. My mailx also does not have the -a option.
cat file | uuencode filename | mailx -s "Test" toemail
Thank you
One way is to construct your input in a temporary file:
cat > tmpfile$$ << END
To: toemail
Subject: Test
X-APP-VOLT: Yes
Hope this works!
END
uuencode filename < file >> tmpfile$$
/usr/sbin/sendmail -i -- toemail < tmpfile$$
Also, I usually use sendmail's -t flag in this case, rather than repeating the recipient:
/usr/sbin/sendmail -i -t < tmpfile$$
If you don't want to use a temporary file, if you want to use a pure pipeline, you can use ( ) to create a subshell to do the construction:
(
echo "To: toemail"
echo "Subject: Test"
echo "X-APP-VOLT: Yes"
echo
echo "Hope this works!"
echo
uuencode filename < file
) | /usr/sbin/sendmail -i -t
(Of course, these days most recipients will probably find it easier to deal with MIME attachments rather than uuencode. It's pretty straightforward to create MIME attachments with a shell script, also.)

Remove all numbers and dashes from text file?

I have an extremely large text file that I need to remove all numbers and dashes from.
Is there any way to do this all at once via command line or perl?
tr is your friend, together with the -d option to delete.
tr -d '[0-9-]' < file
To update your file, you can do tr -d '[0-9-]' < file > tmp_file && mv tmp_file file
Or also sed:
sed 's/[0-9-]//g' file
To update your file, you can use sed -i.bak 's...' file. This will perform in-place editing: file will be updated with the new content and a file.bak backup file will be created.
Test
$ cat a
hello this is -23 and 45 bla-bla
hello bye 23.
$ tr -d '[0-9-]' < a
hello this is and blabla
hello bye .

procmail not piping e-mail content to a file

I have a postfix server and procmail installed and working.
The problem is when I try to output the content of an e-mail to a file.
I have the following script:
/var/log/user1/fooscript.sh
#!/bin/bash
echo "Trying to get e-mail" > success.txt
echo $1 >> success.txt
/var/log/user1/.procmailrc
VERBOSE=off
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/procmail.log
INCLUDERC=$PMDIR/rc.filters
/var/log/user1/.procmail/rc.filters
:0
* ^From:(.*\<)?(test#gmail\.com)\>
| /var/log/user1/fooscript.sh
After sending an e-mail, /var/log/user1/.procmail/rc.filters
contains:
From test#gmail.com Thu Jul 18 05:08:13 2013
Folder: /var/log/user1/fooscript.sh 513
but the success file only shows:
Trying to get e-mail
(empty line)
I've chmod 777 all files and directories, so don't think its a permissions issue.
Any help would be greatly appreciated.
Your script gets the message via standard input (STDIN). Try:
#!/bin/bash
echo "Trying to get e-mail" > success.txt
# append data read from STDIN to success.txt file
cat >> success.txt
BTW for more complicated scripts use custom lock to avoid running two scripts in parallel:
:0 w :fooscript.lock
* ^From:(.*\<)?(test#gmail\.com)\>
| /var/log/user1/fooscript.sh

Sed command returning "invalid command code"

I'm trying to insert this text...
"error.emailNotActivated":"This email address has not been activated yet."
... at line number 5 using sed.
Here is my command so far
translated="This email address has not been activated yet.";
sed -i '' -e '5i\'$'\n''"error.emailNotActivated":'"\"$translated\"" local.strings;
I unfortunately keep getting the error message "invalid command code T".
It seems that sed is interpreting the colon as part of a command.
Any suggestions how i can avoid this?
EDIT:
Seems like an update error (working with old file d'oh...)
the above expression works fine as do the other suggestions.
Why are you fighting with sed for this? It's trivial in awk:
awk -v line='"error.emailNotActivated":"'"$translated"'"' '
NR==5{print line} {print}
' file
or:
awk -v line="\"error.emailNotActivated\":\"${translated}\"" '
NR==5{print line} {print}
' file
Are you looking for something like this?
$ seq 1 5 > file
$ cat file
1
2
3
4
5
$ translated="\"error.emailNotActivated\":\"This email address has not been activated yet.\""
$ echo $translated
"error.emailNotActivated":"This email address has not been activated yet."
$ sed -i "5i $translated" file
$ cat file
1
2
3
4
"error.emailNotActivated":"This email address has not been activated yet."
5