functions not working


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers functions not working
# 1  
Old 12-27-2001
Data functions not working

I have the following functions but when I run SelectQmgr from a Menu Selection it doesn't do anything.
Code:
SelectQmgr ()
{
qmgrlist=`ls /var/mqm/qmgrs/  | grep -v @SYSTEM`
qmgrcount=`ls /var/mqm/qmgrs/ | grep -v @SYSTEM | wc -l`
if [ "$qmgrcount" = "1" ]
then
  echo "$qmgrlist QManager will be used "
  QMGR=$qmgrlist 
elif [ "$qmgrcount" = "0" ]
 then 
  echo " No QManagers found or defined on this System "
  exit
elif [ "$qmgrcount" = "2" ]
 then
WhatQmgr
fi
}

WhatQmgr ()
{
 PS3="Select A QManager"
 select qmgrchoice in $qmgrlist 
  do 
  QMGR=$qmgrchoice
  echo "$qmgrchoice QManager was selected" 
break
done
}

added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 03:21 PM..
# 2  
Old 12-28-2001
After you set qmgrcount, put this as the next line:
echo qmgrcount = $qmgrcount > /dev/tty

Without seeing the complete script I cannot tell how you have standard out redirected at the time the function runs. So I think it's safer to send the output directly to /dev/tty.

Notice that some garbage in /var/mqm/qmgrs could easily set the count to 3 or something. Would would you expect your first function to do then?
# 3  
Old 12-28-2001
Temp solution

Perderabo,

I figured out that the number was ending up in the 8th field so I cut out the 8th field and now it works fine.

qmgrcount=`ls /var/mqm/qmgrs/ | grep -v @SYSTEM | wc -l | cut -d' ' -f8`

You bring up a good point. If there is garbage in that directory I guess I could live with it and clean it up, but if there are more than 3 files I would need to insert greater than.

Is this how I could do it?

elif [ "$qmgrcount" -gt "2" ]
# 4  
Old 12-28-2001
Re: Temp solution

Quote:
Originally posted by darthur
Is this how I could do it?

elif [ "$qmgrcount" -gt "2" ]
That would work, but I would go with just:
else
# 5  
Old 12-28-2001
How would I specify a number range?

If I wanted to select a range from 2-9 would this work?

elif [ "$qmgrcount" = "2-9" ]
# 6  
Old 12-28-2001
Re: How would I specify a number range?

Quote:
Originally posted by darthur
If I wanted to select a range from 2-9 would this work?

elif [ "$qmgrcount" = "2-9" ]
You could do:
elif [ "$qmgrcount" -ge 2 -a "$qmgrcount" -le 9 ]

but I really prefer [[ to [ so I would rather:
elif [[ $qmgrcount -ge 2 && $qmgrcount -le 9 ]]

but not all shells have [[. My favorite way is:
elif ((qmgrcount>=2 && qmgrcount<=9))

but again not all shells have ((.
# 7  
Old 12-28-2001
One Step Back

Perderabo,

I tried your suggestion....

echo qmgrcount = $qmgrcount > /dev/tty


but this just outputs "qmgrcount =" when it gets to this part of the function.


A related problem......

I am having problems with the $QMGR variable. When I try go back and run the function WhatQmgr Menu, it doesn't change the QMGR variable to the one I have selected. How do I overwrite or change the $QMGR varible on the fly?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Disk Space Utilization in HTML format working in one environment and not working on the other

Hi Team, I have written the shell script which returns the result of the disk space filesystems which has crossed the threshold limit in HTML Format. Below mentioned is the script which worked perfectly on QA system. df -h | awk -v host=`hostname` ' BEGIN { print "<table border="4"... (13 Replies)
Discussion started by: Harihsun
13 Replies

2. Shell Programming and Scripting

Working web service call not working with curl

Hello, Newbie here, I have a perfectly well working web service call I can issue from chrome (PC Windows 10) and get the results I want (a dimmer being turned on in Fibaro Home Center 2 at level 40) I am not allowed to post urls but the below works with http and :// and... (3 Replies)
Discussion started by: abigbear
3 Replies

3. Shell Programming and Scripting

Automating pbrun /bin/su not working, whenever manually it is working using putty

I am trying to automate a script where I need to use pbrun /bin/su but for some reason it is not passing thru the pbrun as my code below. . ~/.bash_profile pbrun /bin/su - content c h 1 hpsvn up file path I am executing this from an external .sh file that is pointing to this scripts file... (14 Replies)
Discussion started by: jorgejac
14 Replies

4. Shell Programming and Scripting

Menu with working functions

I am creating a menu currently that makes use of functions to complete each selected option but running into a bit of trouble calling them into action still fairly new with using functions correctly so any insight is appreciated. here is my code so far #!/bin/bash #Last updated on 05/14/14 ... (4 Replies)
Discussion started by: Backtickcruise
4 Replies

5. Red Hat

Nslookup working but ping not working at windows client

Hi Team we have created a DNS server at RHEL6.2 environment in 10.20.203.x/24 network. Everything is going well on linux client as nslookup, ping by host etc in entire subnet. We are getting problem in windows client as nslookup working as well but not ping. all the firewall is disabled and... (5 Replies)
Discussion started by: boby.kumar
5 Replies

6. UNIX for Dummies Questions & Answers

Working of exec family of functions

Hi, I am studying exec family of functions.Its man page says,it replaces the current process image with a new process image. If it replaces the binary,then after returning back,how does it get the previous parameters of the process which called exec?As replacing process image means replacing... (5 Replies)
Discussion started by: Radha.Krishna
5 Replies

7. Programming

Working of exec family of functions

Hi, I am studying exec family of functions.Its man page says,it replaces the current process image with a new process image. If it replaces the binary,then after returning back,how does it get the previous parameters of the process which called exec?As replacing process image means replacing all... (1 Reply)
Discussion started by: Radha.Krishna
1 Replies

8. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

9. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

10. Linux

FTP not working under Linux but working under any other OS ??? Very strange

Dear all, I am totally despaired and puzzled. Using Filezilla under Windows under the same network as our Linux servers is working. Using FTP command-line client under any of our Linux debian servers is not working ! I tried with different FTP servers -> same problem ! All commands are... (12 Replies)
Discussion started by: magix_ch
12 Replies
Login or Register to Ask a Question