AWK help
hai all,
Very frequrently we need to kill all pending jobs for some printers and the queue has so many process..So am preparing the below script to kill the process lpstat gives the below hp2_027003158-1048902 oracle 23552 Thu 26 Apr 2012 09:27:48 AM AST hp2_027003158-1049585 oracle 22528 Sat 28 Apr 2012 07:37:13 AM AST hp2_027003158-1049587 oracle 21504 Sat 28 Apr 2012 07:37:59 AM AST hp2_027003158-1051259 oracle 27648 Sun 29 Apr 2012 01:46:40 PM AST hp2_027003158-1051312 oracle 25600 Sun 29 Apr 2012 02:03:17 PM AST {code} p=`lpstat | grep -i 027003158 grep -v grep | awk '{ print $1}'` for i in $p do echo $i kill -9 $i done {code} But $1 in awk retrieves the complete like below hp2_027003158-1048902 .How can I take the ID only 1048902 out of it ? Kai |
Change the awk program to { gsub( /^.*-/, "", $1 ); print $1 }
|
Quote:
Kai |
Also, I don't think you need grep there at all. Awk can do it as well:
awk '/027003158/ {..........}' |
Quote:
Code:
'{ gsub( /^.*-/, "", $1 ); print $1 }' |
Quote:
{code} p=`lpstat | grep -i 027003158 grep -v grep | awk '{ print $1}'` {code} Can you help me in inserting awk '/027003158/ {..........} in my above command .. Thanks Kai |
Quote:
Code:
lpstat | awk '/027003158/ { gsub( /^.*-/, "", $1 ); print $1 }' |
If these are print jobs, shouldn't you use cancel http://linux.die.net/man/1/cancel-cups ?
|
All times are GMT -5. The time now is 01:30 PM. |