en@frrom
17th September 2008, 17:20
Does anyone know of a way to send a parameter like <timestamp> along with a device output path, in order to create unique files? Such arguments can be extremely usefull for job processing.
Example:
/${BSE}/tmp/output &<timestamp> .txt
Thanks,
En
norwim
17th September 2008, 18:42
Hi there,
why don't you use a script as a printer? The printer definition in Baan looks something like this:
Drucker : EMD1
Bezeichnung : FS 1700 1.Schacht Export
Druckerart : Direkt
Locale : ISO-8859-1 Western Europe - 8 bit
Drucker
Treiber : br1250A4h
Warteschlange : emd1.sh %d %s
Papierart : A4 E A4 format mittel Schriftart
Linker Rand : 0 Seitenvorschub : Ja
The "script" does something simple like
timestamp=`date +%s`
cat $1 > dat$timstamp.txt
cat $1 | lp -d fixprinter
In this example the printed output was still wanted, therefore a driver was specified. if no
output on printer is necessary, you can use ttstpconv likewise.
There's one thing that often goes wrong and gets me confused all the time:
the script should be located in $BSE/bin and have the appropriate execution rigths for group bsp, otherwise simply NOTHING happens, no error or logfile entry occurs. :-)
hth
Norbert
NPRao
17th September 2008, 22:31
Just an idea, try to add this piece of code and see if it works -
boolean job.process 4R Indicates if process is started by a job.
if job.process then
spool.fileout = spool.fileout &
sprintf$("%u(%02m/%02d/%04Y)-%U(%02h%x%02m%x%02s:%a)",
utc.num(), utc.num())
endif
sushil
18th September 2008, 08:25
Hi,
the following code worked for me , you can try this.
curr.dt = date.num()
indate = date.to.inputstr$(curr.dt,"%D002,3",8)
spool.pg.length = 9999
spool.fileout = "C:\filename"& str$(indate)&".txt"
Regards,
Sushil Kumar Mudaliar
en@frrom
18th September 2008, 13:19
Hey guys, thanks for your input.
Norbert,
How would you apply your suggestion for my requirement? I don't want output to a printer, I just want to add a timestamp the selected output file. For instance, if outputfile is /export/tmp/output.txt I want instead /export/tmp/output18092008120000.txt
NPRao & Sushil,
You both suggest solutions which require modifying the program scripts. Of course it is easily done that way, but I want a solution in which I can add it to the device settings, or even much better, user can add on the form during runtime in ttstpconv or in the output settings for jobs...
Regards,
En
norwim
18th September 2008, 14:16
Hi there,
first of all thx to nprao and sushil - although we have some applications which read device names from files into spool.device, I didn't know spool.fileout yet. Great!
@en@ffrom:
create a file timestmp.sh in $BSE, see that owner and group ist bsp and it is executable.
##Start of file timestmp.sh ##
timestamp=`date +%s`
cat $1 > /export/tmp/output$timstamp.txt
##End of file timestmp.sh ##
In Baan create a printer called FILETIMSTP (or whatever)
Description: Printing to File /export/tmp/outputTIMESTAMP.txt
Printertype: Direct (!!!!)
Locale: ISO-8859-1 (or whatever)
Driver: hplj4 (any will do)
Queue: timestmp.sh %s
Paper: A4 (any will do)
If you wish to use a printer, where the user can enter the desired filename ,have a look at ASCIIF
hth
Norbert
en@frrom
18th September 2008, 15:23
Heya Norbert,
I do want to have the user fill in the path or for jobs fill in the path in the job settings, I just want the shell script to add a timestamp to it... Can I achieve that with your suggested solution as well...?
Regards,
En
norwim
19th September 2008, 11:51
jup, use ttstpconv and the following script, it will append the filename choosen in the printer dialog with a timestamp :
---------start of script-----
firsttoken=`echo ${1:0:1}`
prefix="/home/$USER/"
#if string doesn't begin with slash, it is not an absolute filename
#and therefore has to be preceeded with the users homedir
if [ .$firsttoken = "./" ]
then
#nope,absolute path was used
prefix=""
fi
filename=$prefix$1
timst=`date +%Y%m%d%H%M%S`
newfilename=$filename$timst
mv $filename $newfilename
-------end of script-----------------
hth
Norbert
en@frrom
19th September 2008, 12:18
Norbert,
Sorry for my slow understanding, but how/where do I call this script? I created the script timestamp.sh containing the code you send me. Now how do I apply it? Can I just apply it to my device settings? If yes, in which field? Let's say I have device 'ASCIF' of type 'rewrite file', program ttstpconv and argument 'ascii', where do I add my timestamp script? Or even better, could I apply it during runtime? In other words, choose while printing a report whether or not I want to print a timestamp...?
Thanks again,
En
norwim
19th September 2008, 14:34
sorry, I am in a hurry:
Konv.prog: ttstpconv
Argument: ASCII\/path/scriptname %s
Path: SOME SUGGESTION FOR FILENAME
change permitted: yes
pagelength: 55 (doesn't matter)
Check permissions of script
hth
Norbert
sushil
19th September 2008, 14:34
Hi,
May be you could try this .
1.create a device.
2.add a script to it .
with the date added to the user input filename like the code below:
cust .device script.
function read.main.table()
{
tmp.file = creat.tmp.file$( bse.tmp.dir$() )
wait.and.activate("ttstpconv", argv$(1), tmp.file, argv$(3),argv$(4))
indate = date.to.inputstr$(date.num(),"%D002,3",8) |added
local.path = strip$(spool.fileout)&str$(indate)&".txt" |added
err = server2client(tmp.file, local.path, 1)
if (err) then
message("Error %d copying file to PC (may not have permission)", err)
endif
}
Regards,
Sushil Kumar Mudaliar
en@frrom
22nd September 2008, 12:45
Hello Norbert, Sushil,
Sushil,
Your suggestion is obviously a possibility but I did not want to create an extra script for this. I wanted to know if this is possible without a script, just by setting an argument/variable or so..
Norbert,
Your suggestion also requires a kind of a script, but still preferred since it is a small unix script...
I tried your suggestion and it works if I adjust your proposed script. From your suggested
---------start of script-----
firsttoken=`echo ${1:0:1}`
prefix="/home/$USER/"
#if string doesn't begin with slash, it is not an absolute filename
#and therefore has to be preceeded with the users homedir
if [ .$firsttoken = "./" ]
then
#nope,absolute path was used
prefix=""
fi
filename=$prefix$1
timst=`date +%Y%m%d%H%M%S`
newfilename=$filename$timst
mv $filename $newfilename
-------end of script-----------------
I shrank it to
---------start of script-----
filename=$1
timst=`date +%Y%m%d%H%M%S`
newfilename=$filename"_"$timst
mv $filename $newfilename
---------end of script------
The check on fixed path is not necessary, because during runtime the correct (full) path is passed in both cases, whether it concerns a fixed path or just a filename under /home/$user..
The next step to optimization would be to find a way to send this timestamp along as an argument or so in the 'select device' dialog (ttstplopen) for any output-to-file-device, instead of having to adjust & allocate a specific device for this purpose. Like this you can decide for each device every time at runtime whether you want a timestamp added or not...
Regards,
En
NPRao
23rd September 2008, 02:09
I shrank it to
---------start of script-----
filename=$1
timst=`date +%Y%m%d%H%M%S`
newfilename=$filename"_"$timst
mv $filename $newfilename
Let's just shrink it to a 1-liner ;)
cp $1 $1"_"`date +%Y%m%d%H%M%S`
copy than move to be safe :)
The next step to optimization would be to find a way to send this timestamp along as an argument or so in the 'select device' dialog (ttstplopen) for any output-to-file-device, instead of having to adjust & allocate a specific device for this purpose. Like this you can decide for each device every time at runtime whether you want a timestamp added or not...
In that case the better option is to use Sushil's code and ignore the server2client() and add this function to make it generic for any file to be spooled to display browser or redirect to a device:
function extern void print.file( const string fname(),
[string devc(14)])
{
DLLUSAGE
Print the file with spooler option with different devices choices
ENDDLLUSAGE
long fp, splid, mode, devtype
string buffer(1024), dev.desc(50)
if get.argc() = 2 then
devc = get.string.arg(2)
mode = 0
if tt.device(devc, dev.desc, devtype) then
splid = spool.open("", devc, 0)
else
splid = spool.open("", "", 1)
endif
else
splid = spool.open("", devc, 1)
endif
if splid > 0 then
fp = seq.open(fname, "r")
if fp < 0 then
mess("zmadms0036", 1, fname) |* File Opening Error: %1$s
return
endif
while seq.gets(buffer, 1024, fp) = 0
spool.pr.line = buffer
spool.line()
endwhile
e = seq.close(fp)
spool.close()
endif
}
Disclaimer: I have not tested this function against a direct printer (lp -d filename) as we use Windows Network Printers.
csecgn
27th September 2008, 12:02
By writing your own conversion program (like ttstpconv) you can also do a lot of funny things :rolleyes:.
We currently use this way for "batch printing" because we need a special order of print jobs (one landscape and directly after this one or more portrait. All are single reports/printouts.) and our external print server at another location sometimes "re-arranges" the order of the print jobs to a new sort. So we concatenate the single jobs to one big one within the conversion program before really sending to the printer.
Back to your question:
In a conversion program you can modify the output pathes in any way you like by copying the original tmp file to a new name/path/printer/... without modifying your program script. Because you have full access to Baan functionality/tables you could i.e. create a table whith rules for the output file depending on the printername/session/user. So the user(/jobs?) wouldn't need to know/need to enter pathes and so on.
Just an idea
hth
Regards
Christof