Sponsored Content
Homework and Emergencies Homework & Coursework Questions Incrementing Variable resets outside of while loop Post 302394742 by vbe on Friday 12th of February 2010 11:13:30 AM
Old 02-12-2010
????
Modified ps in order to get something on my HP-UX box
It didnt like the last if test...modified also...)
Code:
#!/bin/sh
      count=0
      who | cut -f1 -d" " > temp
      cat temp
      rm temp
      echo "Enter the user whose processes you would like to see"
      read username
      #ps -l -u $username 2>/dev/null
      ps -efl | while read line
      do
        carl=`echo $line | cut -f3 -d" "`
        if [ "$carl" = "$username" ]; then

          #count=`expr count="$count" + 1`
          (( count= $count + 1 ))

                #count is displayed correctly
          echo $count

          echo $line
        fi
      done

      echo "Count : "$count
      echo "That's all"

      #at this point "count = 0"

      if [ "$count" -eq 0 ]; then
        echo "Either that user does not exist or is not running"
      fi

and so execution:
Code:
"cpt_in_while" 32 lines, 741 characters 
ant:/home/vbe $ cpt_in_while   
vbe
suni
vbe
vbe
vbe
vbe
vbe
vbe
vbe
vbe
boss
dave
Enter the user whose processes you would like to see
vbe
1
2001 S vbe 19220 19187 3 168 24 6f6b9380 995 5f0af280 Jan 20 pts/2 91:10 top
2
2001 S vbe 19185 1 7 154 24 6d0c4300 226 b52c00 Jan 20 ? 15:55 /usr/bin/X11/dtterm -displ
3
1 S vbe 14049 19288 0 154 24 9fbc9180 264 b52c40 Jan 28 pts/0 0:00 ssh ramix02
4
1 S vbe 4082 19185 0 154 24 6dd3e0c0 91 a10e0128 Jan 25 pts/9 0:00 /usr/bin/ksh
5
1 R vbe 22371 22361 2 186 24 9cbc17c0 45 - 17:06:27 pts/6 0:00 ps -efl
6
1 S vbe 19231 19185 0 158 24 810c81c0 96 6bec9040 Jan 20 pts/7 0:00 /usr/bin/ksh
7
1 R vbe 22361 9224 5 187 24 949e4d80 80 - 17:06:23 pts/6 0:00 /bin/sh ./cpt_in_while
8
1 S vbe 9224 19185 3 158 24 65bb6c40 99 8aab0040 Jan 22 pts/6 0:00 /usr/bin/ksh
9
1 S vbe 26803 26727 0 154 24 6dd3e840 296 b52c00 Jan 29 pts/11 0:00 ssh -X ramix03
10
1 S vbe 28783 19185 0 154 24 8aaa1440 97 67d7eca8 Feb 4 pts/3 0:00 /usr/bin/ksh
11
2001 S vbe 19195 19187 0 154 18 810c8300 1624 b52c80 Jan 20 pts/2 58:16 gpm
12
1 S vbe 26727 19185 0 158 24 61ec2d40 91 95038040 Jan 29 pts/11 0:00 /usr/bin/ksh
13
1 S vbe 19187 19185 0 158 24 91045880 91 95449040 Jan 20 pts/2 0:00 /usr/bin/ksh
14
1 S vbe 22604 19185 0 158 24 62e05e00 91 6a224040 Feb 11 pts/10 0:00 /usr/bin/ksh
15
1 S vbe 24918 22604 0 154 24 6bdb96c0 57 6c7e14e8 Feb 11 pts/10 0:00 more start_objectspawner
16
1 S vbe 19288 19185 0 158 24 8a724800 95 6ca60040 Jan 25 pts/0 0:00 /usr/bin/ksh
17
1 R vbe 22374 22361 1 186 24 94ed3540 6 - 17:06:27 pts/6 0:00 cut -f3 -d
18
1 R vbe 22375 22374 1 186 24 62a8e080 96 - 17:06:27 pts/6 0:00 /bin/sh ./cpt_in_while
19
1 S vbe 19224 19185 0 154 24 6bd234c0 97 6a6704e8 Jan 20 pts/4 0:00 /usr/bin/ksh
Count : 19
That's all
ant:/home/vbe $

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

incrementing a for loop

I have, LIST="a b c d e" for word in $LIST do echo $word done would give me a b c d e With the first iteration of the for loop, I get "a" as the result. Is it possible that I get both "a" and "b" in only the first iteration. In the next iteration I get "c" and "d" and so on.... (2 Replies)
Discussion started by: run_time_error
2 Replies

2. Shell Programming and Scripting

New iteration of for-loop without incrementing?

Another question, is it possible to, in a for-loop incrementing until it reaches a certain number, to have it loop again without incrementing? Just have it drop what it is doing when it reaches this command and start again at the same number it was at? I know I could make a while loop and just... (0 Replies)
Discussion started by: jeriryan87
0 Replies

3. Shell Programming and Scripting

Need help with incrementing date in while loop.

I need to execute a KornShell (SunOS 5.9) script against a range of dates: endDate=20080804 extractDate=20080401 while ; do batch < scripts/myshellscript.sh $extractDate ## add 1 day to extractDate ## done My question is how do I increment the extractDate variable and still have it... (3 Replies)
Discussion started by: Robert W.Mills
3 Replies

4. Linux

Incrementing the date stored in the variable

Hi all, I have a variable with date as 20080831 . Now I want to increment it as 20080901 and so on.Is there any command for this. Please help me. thanks rameez (1 Reply)
Discussion started by: rameezrajas
1 Replies

5. Shell Programming and Scripting

Incrementing a variable is not happening

Hi All, Iam trying to increment a variable Following is the code #!/usr/bin/ksh i=1; i='expr $i+1'; echo $i; Output: expr $i+1 not able to understand why its happening in that way i was expecting result as 2... if the above method is worng .. can you help how i can get... (3 Replies)
Discussion started by: kiranlalka
3 Replies

6. Shell Programming and Scripting

Incrementing in while loop

echo "Enter Starting id:" echo "" read rvst_strt_idxx echo "" echo "Enter Closing id:" echo "" read rvst_clsn_idxx FIELD1=$rvst_strt_idxx FIELD2="USER" FIELD3="TEST" FIELD4="12345" FIELD5="00000" echo "" echo "INSERT INTO TABLE( FIELD1, FIELD2, FIELD3, FIELD4, ... (7 Replies)
Discussion started by: ultimatix
7 Replies

7. UNIX for Dummies Questions & Answers

Incrementing Variable Names

Hi, I am using BASH. I have encountered a situation where the following is necessary (but I am not sure how to do it): #Define multiple arrays, whose names only differ by a number: ARRAY_1=(1 2 3) ARRAY_2=(4 5 6) ARRAY_3=(7 8 9) #Define ARRAY_AMOUNT, the number of arrays. In this case... (1 Reply)
Discussion started by: msb65
1 Replies

8. UNIX for Dummies Questions & Answers

Incrementing variable in for

Hi, want to increment a variable in a for loop like this: for (( c=$total-1; c>=0; c-- )) do if ; then maximo=$valores fi done But it gives the error: No such file or directory How can i do this only incrementing the c variable? Thanks (8 Replies)
Discussion started by: limadario
8 Replies

9. Shell Programming and Scripting

incrementing the variable name along with the data?

Hello folks. I am trying to increment my variable names to match a counter that is to be used later on... Basically, i have a for loop that lists directories (for example TEST_OS DVP_OS PROD_OS ) but this loop is not static, it may contain 3 directory once and the next run 5 directories. I... (6 Replies)
Discussion started by: Stephan
6 Replies

10. Shell Programming and Scripting

Loop counter resets by itself

Hi! Can anyone explain this? The counter CDR_count should go on forever, but it suddenly resets at every step of the FOR loop (I know this because $_file has exactly 378 records). However, the counter reset is OUTSIDE the FOR loop. What's going on?? #!/bin/bash if || ; then echo ... (8 Replies)
Discussion started by: Flavius
8 Replies
PTS_QUIT(1)						       AFS Command Reference						       PTS_QUIT(1)

NAME
pts_quit - Exit from pts interactive mode SYNOPSIS
pts quit [-cell] <cell name> [-noauth] [-localauth] [-force] pts q [-c] <cell name> [-n] [-l] [-f] DESCRIPTION
The pts quit command exits from pts interactive mode. The command can be run from the command line or interactively, but on the command line it does nothing and is therefore of questionable utility. CAUTIONS
Prior to OpenAFS 1.4.5 and OpenAFS 1.5.23, the pts quit command was only available on Unix or Linux and when OpenAFS was compiled with the supergroups option (disabled by default). As of OpenAFS 1.4.5 and 1.5.23, it is always available. OPTIONS
Although they have no effect, pts quit takes the following standard pts options: -cell <cell name> Names the cell in which to run the command. For more details, see pts(1). -force Enables the command to continue executing as far as possible when errors or other problems occur, rather than halting execution at the first error. -help Prints the online help for this command. All other valid options are ignored. -localauth Constructs a server ticket using a key from the local /etc/openafs/server/KeyFile file. Do not combine this flag with the -cell or -noauth options. For more details, see pts(1). -noauth Assigns the unprivileged identity anonymous to the issuer. For more details, see pts(1). OUTPUT
This command produces no output. EXAMPLES
Here is an example of a pts interactive session: % pts interactive pts> quit % SEE ALSO
pts(1), pts_interactive(1) COPYRIGHT
Copyright 2007 Jason Edgecombe <jason@rampaginggeek.com> This documentation is covered by the BSD License as written in the doc/LICENSE file. This man page was written by Jason Edgecombe for OpenAFS. OpenAFS 2014-04-08 PTS_QUIT(1)
All times are GMT -4. The time now is 02:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy