I have a korne/bourne shell script which fits in an existing script and collects data for multiple users.
I could write the scripts with one output to one file which has the data collection. The program is that it appends the file each time the script runs.
Note :
The scipt is all about collecting no. of pages printed by each users, each time user prints a job it has to collect the no. of pages and add it to field for the existing user entry , instead of having an additional entry for the same user.
The Printing job script already exists and functional.
--------------------------------------------------------------
# This program will collect the no_of_pages data everytime the user successfully queues his print jobs
# The program will run after user print request is queued
# This script should be added after print spooling command
pusr=`whoami`
ls | grep pusg
if [ $? != 0 ]
then
echo "$pusr $no_of_pages" > pusg
chmod 777 pusg
touch npt
chmod 777 npt
else
cat pusg |grep -w $pusr
if [ $? = 0 ]
then
npctr=`grep $pusr pusg |awk '{print $2}' |sort -n |tail -1`
npctr=`expr "$no_of_pages" + "$npctr"`
echo "$pusr $npctr" >> pusg
sort -nr +1 pusg > npt
else
echo "$pusr $no_of_pages" >> pusg
fi
fi
--------------------------------------------------------------
The pusg file gets appended everytime even if the user entry already exists in this file.
Please suggest me the way to write the changes in the second field of the entry for the existing user without adding one more entry as it does in my script (echo "$pusr $npctr").
Secondly let me know can I apply pusg file location and permissions so that users only use it within the script and should not tamper it.
Expecting your kind help ASAP.
thank
Ashraf