Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ability to print a report on request

Status
Not open for further replies.

confuseddddd

Programmer
May 22, 2003
53
US

Need to create a script that will take the current user id and search an audit trail directory for the current date and user id (both of these are part of the file name) and then print the file.

Audit Trail Directory has file names like:
20030924_002.UUU.RPT
20030925_I01.YYY.RPT

1) How can I pull in the user id???
`date +%Y%m%d`_???.${uid}.RPT


2) Can I loop through to print the file(s)???
there could be one day being printed or one
week or one month, based on the user id.

Assuming $uid is the 3 character ID.

for $file in $PATH_TO_FILE/`date +%Y+m+d`_???.${uid}.RPT`
do
echo "Printing $file"
lp -q $LP $file

Anyone have any ideas?????
 
to pull in the user id, it depends on the flavor of unix. in hp, it would be `id -u`
in solaris, `id -ur`
in aix, `id -u`
 
Can anyone see what is wrong with this???
PATH_TO_FILE=/test/AUDITIN;export PATH_TO_FILE
for file in $PATH_TO_FILE/`date +%Y%m%d_I01.${uid}.RPT` do
echo "Printing $file"
lp - $LP file
done

The line prints:
printing /test/AUDITIN/20030929_I01.UUU.RPT
but then the system hangs and does not return back.

What other piece of code do I need???

Also I would like the flexability to use a "wildcard" for all the AUDIT directories, AUDITIN, AUDITINT and would like the flexability to use a "wildcard" for the file name, instead of always looking for I01, need the ability to look for I02, I01, 001 and 002.
 
Code:
> lp - $LP file
      ^
this space seems unwanted
What is the value of $LP ?
I guess the system doesn't hang but waits for standard input to print.
Provided $LP=NameOfSomePrinter you can try this:
Code:
lp -d$LP $file
For your 2nd question, try something like this:
Code:
mydate=`date +%Y%m%d`
for file in /test/AUDITIN*/${mydate}_[I0]0[12].$uid.RPT`
do
  echo "Printing $file"
  lp -d$LP $file
done

Hope This Help
PH.
 
Also "do" either needs to be on a separate line to "for", or alternatively put a semi-colon in front of it:

[tt]for file in $PATH_TO_FILE/`date +%Y%m%d_I01.${uid}.RPT` ; do[/tt]

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top