dmcnally
11th April 2014, 00:59
Using "Maintain Device Data" (ttaad3100m000) I am trying to create a device that will rename the output file and then email it.

I have written a bash script (copyrpt.sh) as follows:

#!/bin/bash
NEWFILE=${BSE}/edi/reports/baanrpt.`date +%Y%m%k%M%S`
export NEWFILE
mv ${HOME}/baanrpt ${NEWFILE}
/opt/csw/bin/mutt -s "edi report" -a ${NEWFILE} -- dmcnally@hufna.com < embody.txt

The script works perfectly from the command line.
However when I use it in the definition of the device (see attached screen shot). only the mv command gets executed and the mutt command is essentially ignored. I even tried putting the mutt command in a separate script and calling it from the copyrpt.sh script to no avail.

Does anyone have any idea why this would not work as an argument in a device definition?

Thanks,

Dave M.

mark_h
11th April 2014, 06:18
On your device - try putting ASCII:/usr/local/bin/emdevice/copyrpt.sh %s. I think you need to pass it the file name. This is just a guess - I know at one time we had a device that ran a script, but we have not used it for years and I can't find it. I just seem to recall having issues with using \.

Now a days what I would do is write my own ttstpconv. You can see an example in the code and utilities forum. This is a 3gl program. What I would do is in the first part I would run ttstpconv on the file to convert to ascii. At that point I would know the file name - then I would create a unix cmd line like cmd ="copyrpt.sh " & tempfile. Making sure it was quoted right. Then I would run the shell command. Now all you have to do is make sure the command file works from a 3gl program.

Or - below is sample code from a program I wrote not to long ago. It sends the out put - in this case ebom config to a file and emails it to a purchasing agent. Basically I believe you could do all the emailing in a 3gl program used in place of ttstpconv. Potential faults and all are below. :)

function print.po()
{

string cmd(1000) | Unix Command
string temp.file(256) | Temp file name
string email.addr(100) | Email address
domain tcyesno explode.flag

long rc
msg = ""

if tdexi305.subm = tdexi.method.email then
spool.device = "ASCIF"
spool.fileout = creat.tmp.file$( bse.tmp.dir$() )
spool.fileout = strip$(spool.fileout)
rpt_id = spool.open("",spool.device,0)
export("spool.fileout",spool.fileout)
else
spool.device = "D66"
spool.fileout = ""
rpt_id = spool.open("",spool.device,1)
export("spool.fileout",spool.fileout)
endif
spool.close()

stpapi.put.field( "tdpur4401m000", "tdpur999.send", str$(tdpur.dist.vendor) )
stpapi.put.field( "tdpur4401m000", "selection", str$(tcyesno.no) )
stpapi.put.field( "tdpur4401m000", "suno.f", " " )
stpapi.put.field( "tdpur4401m000", "suno.t", "ZZZZZZ" )
stpapi.put.field( "tdpur4401m000", "orno.f",str$(tdexi305.orno))
stpapi.put.field( "tdpur4401m000", "orno.t",str$(tdexi305.orno))
stpapi.put.field( "tdpur4401m000", "comp.f", str$(0) )
stpapi.put.field( "tdpur4401m000", "comp.t", str$(999) )
stpapi.put.field( "tdpur4401m000", "tdpur999.dpas", str$(tcyesno.yes) )
stpapi.put.field( "tdpur4401m000", "prnt.pric", str$(tcyesno.yes) )
stpapi.put.field( "tdpur4401m000", "printed", str$(tdsls.kofl.all) )
stpapi.put.field( "tdpur4401m000", "quan.to.print", str$(tdsls.koqu.ordered.quan) )
stpapi.put.field( "tdpur4401m000", "prnt.options", str$(tcyesno.yes) )
stpapi.put.field( "tdpur4401m000", "prnt.deladro", str$(tcyesno.no) )
stpapi.put.field( "tdpur4401m000", "chgflag", str$(tcyesno.no) )
stpapi.put.field( "tdpur4401m000", "chgordnum", str$(0) )
stpapi.put.field( "tdpur4401m000", "chgorddte", str$(0) )
stpapi.set.report("tdpur4401m000","rtdpur440101000", spool.device, msg)
stpapi.continue.process( "tdpur4401m000", msg)
if(strip$(msg)<>"") then
message("Err. %s PO:%d", msg, tdexi305.orno)
endif
stpapi.end.session( "tdpur4401m000" )



if tdexi305.subm = tdexi.method.email then
select tccom001.emno, tccom001.info
from tccom001
where tccom001._index1 = {:tdexi305.buyr}
as set with 1 rows
selectdo
endselect
if isspace(strip$(tccom001.info)) then
message("No email address for buyer %d.", tdexi305.buyr)
return
endif
| It was easy to use order number, so I did, but it will break if
| the series changes.
if tdexi305.orno>700000 and tdexi305.orno<=799999 then
explode.flag = tcyesno.yes
else
explode.flag = tcyesno.no
endif

cmd = "unix2dos " & strip$(spool.fileout) & " " & strip$(spool.fileout)
rc = shell(cmd, SHELL_NO_OUTPUT)
temp.file = creat.tmp.file$(bse.tmp.dir$())
temp.file = strip$(temp.file)
cmd = "uuencode " & spool.fileout & " " & strip$(str$(tdexi305.orno)) & ".txt >>" & temp.file
rc = shell(cmd, SHELL_NO_OUTPUT)

spool.fileout = creat.tmp.file$( bse.tmp.dir$() )
spool.fileout = strip$(spool.fileout)
export("spool.fileout",spool.fileout)
stpapi.put.field( "tiedm9410m000", "select.by.order", str$(tcyesno.yes))
stpapi.put.field( "tiedm9410m000", "order.type", str$(tckoor.act.pur))
stpapi.put.field( "tiedm9410m000", "order.number", str$(tdexi305.orno))
stpapi.put.field( "tiedm9410m000", "explode.flag", str$(explode.flag))
stpapi.set.report("tiedm9410m000","rtiedm941011000",spool.device,msg)
stpapi.continue.process( "tiedm9410m000", msg )
stpapi.end.session( "tiedm9410m000" )
if not isspace(msg) then
message("Err. Print config:%s PO:%d", msg, tdexi305.orno)
endif
suspend(500)
cmd = "unix2dos " & strip$(spool.fileout) & " " & strip$(spool.fileout)
rc = shell(cmd, SHELL_NO_OUTPUT)
cmd = "uuencode " & spool.fileout & " " & strip$(str$(tdexi305.orno)) &"-config" & ".txt >>" & temp.file
rc = shell(cmd, SHELL_NO_OUTPUT)


email.addr = strip$(tccom001.info) | Convert to unix file
cmd = "/bin/mailx -s " & quoted.string("Printed Purchase Order (Automated Email)") & " " & strip$(email.addr) & "<" & temp.file
rc = shell(cmd, SHELL_NO_OUTPUT)

seq.unlink(temp.file)
seq.unlink(spool.fileout)
endif
}

dmcnally
11th April 2014, 21:07
Mark,

Thanks for your reply and code.
With some help I got the script to work, using the syntax below.
This puts the report in the body of the email as well as an attachment

/opt/csw/bin/mutt -s "edi report" -a ${NEWFILE} -- dmcnally@hufna.com < ${NEWFILE}


I did try the ASCII:/usr/local/bin/emdevice/copyrpt.sh %s in the device definition to no avail.

So I went back to ASCII\/usr/local/bin/emdevice/copyrpt.sh in the device definition.
It is now working properly with the syntax change in the mutt command noted above.

The reason for this is we have our EDI running via EDI controllers under 2 different users. The default device for both users was notepad. So all the output/reports were going to notepad and cluttering up the screen on the machine were the bshells are running for the EDI controllers.

I can now set the default device to my newly defined EDI CONTR OUT and have all the output go to a folder and to an email account where they can be analyzed.

Thanks again :)

Dave M