Find the answer to your Linux question:
Results 1 to 4 of 4
I have two scripts on a production solaris box to check and clear the print queue. I want to combine these to make my job a lot easier. I always ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Location
    Memphis, TN
    Posts
    65

    [SOLVED] Need help combining two ksh scripts

    I have two scripts on a production solaris box to check and clear the print queue. I want to combine these to make my job a lot easier. I always script in python, but this machine doesn't have it and I don't have rights to install it. Any help on putting these two together will be greatly appreciated!!!

    Script 1 (checks queue):

    #!/bin/ksh
    #
    PATH=/usr/bin:$PATH; export PATH
    #
    #
    TB_TITLE () {
    clear
    echo " "
    echo "\t\t\t\t\t Thomas & Betts"
    echo " "
    echo "\t\t\t\t\tPrint Queue Depth Monitor"
    echo "\t\t\t\t\t `hostname`"
    echo " "; }
    #
    TB_CHOICE_ACT () {
    echo " "
    echo "\t\t\t\tPlease choose from the following-:"
    echo " "
    echo "\t\t\t\t1) Check Print Queue Current Jobs."
    echo "\t\t\t\t2) Exit the Monitor System."
    echo " "
    read CHOICE_ACT?" Enter 1 or 2 (default is 2)- "
    echo " "
    if [ ! $CHOICE_ACT ]
    then
    CHOICE_ACT=2
    fi
    }
    #
    TB_CHOICE_QUEUE () {
    echo " "
    echo "\t\t\t\tName of the queue you would like to check."
    echo " "
    read CHOICE_QUEUE?" Enter Queue (default is all queu
    es)- "
    echo " "
    }
    #
    #
    TB_TITLE
    TB_CHOICE_ACT
    #
    while [ $CHOICE_ACT -ne 2 ]
    do
    #
    TB_TITLE
    TB_CHOICE_QUEUE
    #
    x=1;
    export x
    #
    CHOICE_EXIST=`grep "$CHOICE_QUEUE:" /etc/printers.conf | wc -l`;
    export CHOICE_EXIST
    #
    clear
    #
    if [ $CHOICE_EXIST -gt 0 ]
    then
    #
    echo " "
    echo "Current Print Queue Jobs for the $CHOICE_Q
    UEUE queue at `date`"
    sleep 2
    echo " "
    echo "Please wait ..."
    echo " "
    sleep 2
    PRINT_JOBS=`lpstat -o $CHOICE_QUEUE | wc -l`
    export PRINT_JOBS
    if [ $PRINT_JOBS -gt 0 ]
    then
    lpstat -o $CHOICE_QUEUE
    else
    echo " "
    echo "No print jobs queued on $C
    HOICE_QUEUE."
    echo " "
    sleep 10
    fi
    #
    echo " "
    #
    sleep 10
    #
    TB_TITLE
    TB_CHOICE_ACT
    else
    TB_TITLE
    echo " "
    echo "\t\t\t\tPrinter Queue choice does not exis
    t."
    sleep 10
    fi
    done
    echo " "


    Script 2 (Clears Queue):

    #!/bin/ksh
    #
    ###########
    #
    underon=`tput smul`
    underoff=`tput rmul`
    alloff=`tput sgr0`
    bold=`tput smso`
    blinkon=`tput blink`
    revon=`tput rev`
    #
    #########
    #
    TB_TITLE () {
    echo " "
    echo "\t\t${underon}Thomas & Betts${alloff}"
    echo " "
    echo "\t\tPrint Queue Clearing Facility"
    #
    echo " "
    echo " "
    echo "This will ask for a print queue name and clear all jobs from that queue."
    echo " "
    #
    sleep 0;}
    #
    CHOOSE_QUEUE () {
    #
    PRNQUEUE=zzz.foo.zzz; export P
    RNQUEUE
    #
    while [ $PRNQUEUE != "exit" ] && [ `grep $PRNQUEUE /etc/printers.conf | wc -l` -
    lt 1 ]
    do
    clear
    TB_TITLE
    echo "Please enter the printer queue name. This will repeat unti
    l a VALID"
    echo "PRINTER QUEUE is given. To quit the facility, please type
    ${bold}exit${alloff}"
    sleep 1
    echo " "
    read PRNCHOICE?" Queue Name- "
    echo " "
    if [ $PRNCHOICE = "exit" ]
    then
    echo "\t\t\tYou have chosen to exit the facility
    "
    echo " "
    sleep 1
    exit
    fi
    if [ `grep $PRNCHOICE /etc/printers.conf | wc -l` -gt 0 ]
    then
    echo "You have chosen $PRNCHOICE. Proceeding to
    clear the $PRNCHOICE print queue."
    PRNQUEUE=$PRNCHOICE; export P
    RNQUEUE
    fi
    done
    #
    echo " "
    echo " "
    #
    sleep 0;}
    #
    ##########
    #
    CHOOSE_QUEUE
    #
    sleep 4
    echo "\tStarting queue clearing at `date`."
    echo " "
    lpstat -o $PRNQUEUE | sed 's/ */ /g' 2>/dev/null | grep -v Printer | grep -v lp
    d | cut -d " " -f 1 | xargs cancel 2>/dev/null
    #
    sleep 4
    cd /var/spool/print
    #
    if [ -a $PWD/xf* ]
    then
    if [ `grep $PRNQUEUE xf* | wc -l` -gt 0 ]
    then
    sleep 4
    for i in `grep $PRNQUEUE xf*`
    do
    FILES_TO_DEL=`echo $i | cut -d "
    :" -f 1 | cut -c 3-`
    rm *${FILES_TO_DEL} 2>/dev/null
    done
    #
    lpstat -o | sed 's/ */ /g' | grep -v Printer |
    grep -v lpd | grep $PRNQUEUE | cut -d " " -f 1 | xargs cancel 2>/dev/null
    fi
    fi
    #
    echo " "
    echo "Queue cleared at `date`."
    echo " "
    echo "This script may need to be run again to catch jobs that may"
    echo "have started while this script was running."
    sleep 4
    #
    #########

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I'm kinda busy and can't take the time to actually do coding for you, but I have three alternative suggestions.
    1. Use cat to combine the two scripts into a third script, and run that instead of the other two.

      Or:
    2. If the two scripts are at /complete/path/fred and /complete/path/barney, create a script with the following content, and make it executable:
      Code:
      /complete/path/fred
      /complete/path/barney
      Or:
    3. If you want to ask for a queue name only once, and then do two or more operations with that queue, then inspect the scripts. Actually get your fingernails dirty with ksh scripting. If you're already familiar with php, that means you have some programming skills, and you may not find it all that difficult to pick up a little street ksh knowledge. If you have a question about how ksh works in a particular situation and you can't figure it out yourself, you might get a useful answer if you come back here. You might also benefit by googling this:
      Code:
      ksh tutorial

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Location
    Memphis, TN
    Posts
    65
    Quote Originally Posted by wje_lf View Post
    I'm kinda busy and can't take the time to actually do coding for you, but I have three alternative suggestions.
    1. Use cat to combine the two scripts into a third script, and run that instead of the other two.

      Or:
    2. If the two scripts are at /complete/path/fred and /complete/path/barney, create a script with the following content, and make it executable:
      Code:
      /complete/path/fred
      /complete/path/barney
      Or:
    3. If you want to ask for a queue name only once, and then do two or more operations with that queue, then inspect the scripts. Actually get your fingernails dirty with ksh scripting. If you're already familiar with php, that means you have some programming skills, and you may not find it all that difficult to pick up a little street ksh knowledge. If you have a question about how ksh works in a particular situation and you can't figure it out yourself, you might get a useful answer if you come back here. You might also benefit by googling this:
      Code:
      ksh tutorial

    Hope this helps.
    Thank you for the reply. I know python pretty well. I'll do some research and maybe get the syntax down. Thanks again!!!

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Oops; python, not php. My bad! (*grumble grumble new-fangled languages, can't keep 'em all straight, get off my lawn grumble grumble*)
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...