scripts remember the previous parameter???


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers scripts remember the previous parameter???
# 1  
Old 11-14-2006
scripts remember the previous parameter???

I have a simple script. I have tried this in Bourne, Korn and C shells in my AIX ...no luck

unset STARTQUEUE

# Check parameters
if [ $# != 1 ]
then
echo "*E* Batch Queue parameter is missing"
else
$BATCHQ/bin/setup.sh
STARTQUEUE=$1

# If the queue doesn't exist, create it
if [ ! -d "$QUEUES/$STARTQUEUE" ] ; then
mkdir $QUEUES/$STARTQUEUE
fi

# If the queue log doesn't exist, create it
if [ ! -f "$QUEUES/$STARTQUEUE/queue.log" ] ; then
cp $QUEUES/flag.dat $QUEUES/$STARTQUEUE/queue.log
fi

# If the logs folder doesn't exist, create it
if [ ! -d "$QUEUES/$STARTQUEUE/logs" ] ; then
mkdir $QUEUES/$STARTQUEUE/logs
fi

# Check to see if the queue is already running
if [ -f "$QUEUES/$STARTQUEUE/started.dat" ]
then
echo "*E* Batch Queue ($STARTQUEUE) is already running"
else
# Create a flag file to indicate the queue has started
cp $QUEUES/flag.dat $QUEUES/$STARTQUEUE/started.dat
echo "Batch Queue ($STARTQUEUE) started `date`" >> $QUEUES/STARTQUEUE/queue.log
fi
fi

The problem is that once I run the script, $1 stays in memory (or where ever) and if I DO NOT supply the parameter the second time I run the script, it somehow remembers the script.

for example:
/ $ startq
*E* Batch Queue parameter is missing
/ $ starq dayq
*E* Batch Queue (dayq) is already running
/ $ starq
*E* Batch Queue (dayq) is already running


Any ideas how to erase the value of $1 when I run the over and over?
# 2  
Old 11-14-2006
Works for me.

Code:
./starq dayq
./starq[11]: /bin/setup.sh:  not found
Batch Queue (dayq) started Tue Nov 14 14:50:17 MST 2006

$ ./starq     
*E* Batch Queue parameter is missing

$ ./starq dayq
./starq[11]: /bin/setup.sh:  not found
Batch Queue (dayq) started Tue Nov 14 14:50:38 MST 2006

$ ./starq     
*E* Batch Queue parameter is missing

of course I don't have your setup.sh script and I commented out your system calls to see what is happening but the parameter isn't remaining.
Code:
#! /usr/bin/ksh

unset STARTQUEUE

# Check parameters
#set -x
if [ $# != 1 ]
then
    echo "*E* Batch Queue parameter is missing"
else
    $BATCHQ/bin/setup.sh
    STARTQUEUE=$1

    # If the queue doesn't exist, create it
    if [ ! -d "$QUEUES/$STARTQUEUE" ] ; then
        :
        #mkdir $QUEUES/$STARTQUEUE
    fi

    # If the queue log doesn't exist, create it
    if [ ! -f "$QUEUES/$STARTQUEUE/queue.log" ] ; then
        :
        #cp $QUEUES/flag.dat $QUEUES/$STARTQUEUE/queue.log
    fi

    # If the logs folder doesn't exist, create it
    if [ ! -d "$QUEUES/$STARTQUEUE/logs" ] ; then
        :
        #mkdir $QUEUES/$STARTQUEUE/logs
    fi

    # Check to see if the queue is already running
    if [ -f "$QUEUES/$STARTQUEUE/started.dat" ] 
    then
        echo "*E* Batch Queue ($STARTQUEUE) is already running"
    else
        # Create a flag file to indicate the queue has started
        :
        #cp $QUEUES/flag.dat $QUEUES/$STARTQUEUE/started.dat
    echo "Batch Queue ($STARTQUEUE) started `date`" 
#>> $QUEUES/STARTQUEUE/queue.log
    fi
fi
set +x

Uncomment the "#set -x" and set the shell show you what's going on.
# 3  
Old 11-15-2006
Helo.
Is that the whole script? I mean, does it anything else appart from that? Notice that your script does not exit when there are no parameters. Change this:
Quote:
# Check parameters
if [ $# != 1 ]
then
echo "*E* Batch Queue parameter is missing"
else
into:
Code:
# Check parameters
if [ $# != 1 ]
then
   echo "*E* Batch Queue parameter is missing"
   exit 1
else

and let's see what happens. Check also your shell environment. Just give something like:
Code:
env | grep -i dayq

And check what it shows...
Regards.
# 4  
Old 11-15-2006
Ok that solved the problem.

I removed the contents of setup.sh and reduced it to only the lines that I needed and it now works. Thanks

As for the EXIT. I used to have one, but when I ran the script from root...it logged me out of the system instead of the script. I changed it exit gracefully without an exit.

Ken
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Log Out vs Remember Me

Howdy, I clicked the rememberer me when I log in, and evidently I really do not understand what that means. I had hoped that at least it would remember my user name for the next time that I log in. However, when I log out, I see a message about cookies being removed and one other thing that I... (1 Reply)
Discussion started by: danuke
1 Replies

2. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

3. What is on Your Mind?

Anyone remember this cute unix ad?

It showed a cleaning woman (probably in the evening, after most of the other employees had left work) happily typing commands on a dot matrix terminal (could've been a DEC LA120, IIRC) just because "unix is so easy to use, even a cleaning woman can use it!". If you know where to find a scanned... (2 Replies)
Discussion started by: mathiasbage
2 Replies

4. UNIX for Dummies Questions & Answers

Grep that I should know but I can't remember!

I have a master list of hosts, and a list of bad hosts. I want to filter out the bad hosts from the master list. I was trying a few for loops but it's not providing the desired result: for i in $(cat master_host_list);do grep -iv $i bad_host_list;done | sort | uniq # won't work because it... (5 Replies)
Discussion started by: MaindotC
5 Replies

5. Shell Programming and Scripting

remember processed files

Hello dear community! I have the following task to accomplish: there is a directory with approximately 2 thousand files. I have to write a script which would randomly extract 200 files on the first run. On the second run it should extract again 200 files but that files mustn't intersect with... (5 Replies)
Discussion started by: sidorenko
5 Replies

6. Shell Programming and Scripting

Perl parameter passing between scripts

Hi All, I have two perl scripts say A.pl and B.pl. A.pl interacts with Database and pulllls around 20 column-variables, which needs to be used in B.pl . A.pl calls B.pl, I figured out that there exist a limit on number of arguments being passed as command line argument. A.pl writing to a... (3 Replies)
Discussion started by: coolbhai
3 Replies

7. Forum Support Area for Unregistered Users & Account Problems

Two Login's - Remember only one.

Hi All, Have only recently returned to Unix.com due to other activities (*oh the shame of it all). Anyways, when I initially came back to redesigned/revamped site I couldn't remember any of my logins. I'd originally thought that I'd used the UID of 'Cameron' but couldn't remember any details... (2 Replies)
Discussion started by: Cameron
2 Replies

8. Shell Programming and Scripting

Invoke script depending on previous scripts

Hi, I am in desperate needs for advice! I have a script which would invoke various java programs depending on the input parameter and a script which would perform calculation on the data inputted by the first script. The schedule of the job is like this 1) 10:00 am to 11:00 am: call java... (0 Replies)
Discussion started by: mpang_
0 Replies

9. Shell Programming and Scripting

AWK--does anyone remember it

I am trying to run awk on a 55 page Word document. I wanted to delete every occurrence of <company>, <script>, </scripts> from the file then cut & paste all of the appropriate fields to an Excel spreadsheet. Also the code is suppose to replace the dates in a new format such as "xxxx-xx-xx" ... (2 Replies)
Discussion started by: cnitadesigner
2 Replies
Login or Register to Ask a Question