1833852 Members
1849 Online
110063 Solutions
New Discussion

Formatting output

 
Khashru
Valued Contributor

Formatting output

I am running one script to check the printers of the system and mail it to me. It is working fine. But the format is not good. I want each printer will be in a separate line.

i am using the following script
for i in $(cat /home/mayub/script/printer_name.txt)
do
x=`lpstat -p$i |grep idle`
echo $x
done

The oupput is

printer ausyd01pr305 is idle. enabled since Dec 8 11:07 printer ausyd01pr315 is idle. enabled since Dec 8 11:09 printer ausyd01pr300 is idle. enabled since Jan 24 16:02 printer ausyd01pr306 is idle. enabled since Jan 27 16:37 printer ausyd01pr307 is idle. enabled since Jan 27 16:38 printer ausyd01pr308 is idle. enabled since Jan 27 16:38 printer ausyd01pr311 is idle. enabled since Jan 27 16:39 printer ausyd01pr312 is idle. enabled since Jan 27 16:39 printer ausyd01pr314 is idle. enabled since Jan 27 16:40 printer ausyd01pr330 is idle. enabled since Jan 27 16:40 printer ausyd01pr336 is idle. enabled since Jan 27 16:41 printer ausyd01pr344 is idle. enabled since Jan 27 16:41 printer ausyd01pr345 is idle. enabled since Jan 27 16:42 printer ausyd01pr350 is idle. enabled since Jan 27 16:42 printer ausyd01pr353 is idle. enabled since Jan 27 16:43 printer ausyd01pr359 is idle. enabled since Jan 27 16:43 printer ausyd01pr363 is idle. enabled since Jan 27 16:44 printer ausyd01pr364 is idle. enabled since Jan 27 16:44 printer ausyd01pr365 is idle. enabled since Jan 27 16:45 printer ausyd01pr369 is idle. enabled since Jan 27 16:46 printer ausyd01pr370 is idle. enabled since Jan 27 16:46 printer ausyd01pr372 is idle. enabled since Jan 27 16:47 printer ausyd01pr380 is idle. enabled since Jan 27 16:47 printer ausyd01pr401 is idle. enabled since Jan 27 16:48 printer ausyd01pr351 is idle. enabled since Jan 30 16:12

I want out put like that

printer ausyd01pr305 is idle. enabled since Dec 8 11:07
printer ausyd01pr315 is idle. enabled since Dec 8 11:09
printer ausyd01pr300 is idle. enabled since Jan 24 16:02
printer ausyd01pr306 is idle. enabled since Jan 27 16:37

so on
8 REPLIES 8
Chan 007
Honored Contributor

Re: Formatting output

Hi,

Change your script a bit.

x=`lpstat -p$i |grep idle`
echo $x

instead use

echo $x >> /tmp/p.out

Also each time before starting

rm /tmp/p.out

Chan
Khashru
Valued Contributor

Re: Formatting output

I get the formatted output when i un the script from console. but when i mail it it looses its format. How can i solve that.
Chan 007
Honored Contributor

Re: Formatting output

Try adding "\n" in your script for next line.

That should solve your problem
Chan
Khashru
Valued Contributor

Re: Formatting output

I have tried but having problem.

what will be the syntext

lpstat -p$i |grep idle \n
Chan 007
Honored Contributor

Re: Formatting output

it can be like echo $i \n
Khashru
Valued Contributor

Re: Formatting output

Where should i put that
Muthukumar_5
Honored Contributor

Re: Formatting output

Use as,

while read printer;
do

lpstat -i${printer} | grep idle

done < /home/mayub/script/printer_name.txt

--
Muthu
Easy to suggest when don't know about the problem!
Khashru
Valued Contributor

Re: Formatting output

Problem solved. i have used "\n" in the end of echo line.