Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux HostsFree MagazinesJobs
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Programming & Scripting
Reload this Page [SOLVED] Need help combining two ksh scripts
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Programming & Scripting C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Closed Thread
 
Thread Tools Display Modes
Old 06-25-2008   #1 (permalink)
Just Joined!
 
Join Date: Jun 2008
Location: Memphis, TN
Posts: 47
[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
#
#########
wesley_morris2000 is offline  
Old 06-25-2008   #2 (permalink)
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 1,018
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.
wje_lf is offline  
Old 06-25-2008   #3 (permalink)
Just Joined!
 
Join Date: Jun 2008
Location: Memphis, TN
Posts: 47
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!!!
wesley_morris2000 is offline  
Old 06-25-2008   #4 (permalink)
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 1,018
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.
wje_lf is offline  
Closed Thread



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
 

Free Magazines
Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe
Systems Management News, the newspaper for IT systems administration and data center managers!
Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe
The Enterprise Newsweekly
eWeek is the essential technology information source for builders of e-business.
subscribe
Oracle Magazine
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe
Total Telecom
Total Telecom is "The Economist of the communications industry".
subscribe
More free magazines »



All times are GMT. The time now is 03:20 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.2.0