Search a string for match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Everyone,

I'm writing a little bash script that's going to be integrated into
another application.  The script itself checks if the user has any print
jobs, and if so, lists them.  The user then has the opportunity to
cancel a print job.  Simple enough.

I want to check that the job ID being entered actually exists.  If it
doesn't, the script should let the user know.

My problem is that I don't know how to compare the ID entered against
the list of the user's current print job IDs.  It looks to me like awk
is the way to go, but I'm not sure how to do it.  I've tried a few
different awk statements, but none have worked.

Here's the script in its current form:

#!/bin/bash

until [ "$answer" = 0 ]; do
   JOBS=$(lpq -a | grep `id -un`)
   JOB_IDS=$(lpq -a | grep `id -un` | tr -s " " | cut -d " " -f 3)
   if [ -z "$JOBS" ]; then
      echo "You currently don't have any print jobs."
      echo "Exiting..."
      exit 0
   else
      clear
      echo "Rank    Owner   Job     File(s)
Total Size"
      echo "$JOBS"
      echo ""
      echo -n "Enter the print Job number you want to cancel (0 to
exit)?:  "
      read answer

      # I think there should be a check here, after the first test      
      if [ "$answer" != 0 ]; then

      # the bit bucket is temporary until second check is worked out
         cancel $answer > /dev/null 2>&1
         echo "Job $answer cancelled."
         sleep 1
      
      # an elif here if the print job ID doesn't exist

      else
         echo "No print job selected. Exiting..."
      fi
   fi
done

exit 0

Thanks for any tips!

Regards,

Ranbir

-- 
Kanwar Ranbir Sandhu
Linux 2.6.14-1.1656_FC4 i686 GNU/Linux 
15:06:03 up 8:05, 4 users, load average: 2.55, 1.80, 1.25 



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux