Script Gone Wrong


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script Gone Wrong
# 8  
Old 05-15-2010
Though we don't seem to have the discrepancy on our systems we don't have any scripts which rely on the "uptime" command.
# 9  
Old 05-15-2010
There is a discrepancy but both values are correct.
# 10  
Old 05-15-2010
As the accountant said to the auditor.
# 11  
Old 05-15-2010
If you are logged twice to a system, are you a single user or two ?
# 12  
Old 05-15-2010
Must depend on context.
Some software is licenced by seat and some by connection.
Some software allows multiple users under the same login, some doesn't.
We'd look at the most relevant count.

Where the system is hosting a database the count of active database connections is much more useful than unix login sessions (which might be nil).
Within that there may be rules about multiple connections.


Wonder if the O/P wants number of current sessions or number of different users who have current sessions?
# 13  
Old 05-16-2010
@ygemici, methyl, jlliagre - Thanks alot for the help, i corrected the code, and now its working fine, i should have posted it before handing it in.

i have a question though,
- as for the (date +%H) what does it do?!

as for "users=$(who -u|wc -l)" instead of using "uptime" that was pretty slick, i liked it.

@vidyadhar85's - sorry i forgot to post the errors, here they are, but i guess its a little bit, the guys figured out the erros

Image

Thanks again
let's hope the teacher accepts a modified late assignment :P
# 14  
Old 05-16-2010
Why you din't make change
Code:
time=$(date | cut -d" " -f5 | cut -d: -f1)
#=>
time=$(date '+%H')   # run command date '+%H' to test and read man date

If need arguments, so use "$time", better than $time.
After those you don't get those errors.

Here is maybe more easier to read version, menu has only once, used more pipes, not temp files.

Code:
while
      echo "1. Greet User"
      echo "2. Replace Papper"
      #...
      echo -n "Choice:"
      read choice
do
      if [ "$choice" = 5 ] ; then
         break
      fi

      ###################################
      if [ "$choice" = 1 ] ; then
         #do_some
         continue
      fi

      ###################################
      if [ "$choice" = 2 ] ; then
         #do_some2
         continue
      fi

      ###################################
      if [ "$choice" = 3 ] ; then
         users=$(who | wc -l)
         #...
         continue
      fi

      ###################################
      if [ "$choice" = 4 ] ; then
         who | while read line
         do
            values=($line)
            usertemp=${values[0]}
            #....
         done
         #....

         continue
      fi


      #...
      echo "no such option"
done

This User Gave Thanks to kshji For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

2. Shell Programming and Scripting

What is wrong with my script?

Dear All The following is part of my script: echo ${myarray} mytitle=`awk '{print substr(${myarray}, 0, length(${myarray})-4)}' /dev/null` the echo ${myarray} works fine; however, I keep getting following error for the mytitle=.. part: awk: line 1: syntax error at or near { awk: line... (3 Replies)
Discussion started by: littlewenwen
3 Replies

3. Shell Programming and Scripting

Can anyone tell me what's wrong with my script

Hi... I am fed up in file handing with array for comparing.... 1st I want save first 2 columns of file 1 I tried like this,, {getline< "file1";ln=$1; lt=$2}then I read second file's 1st and 2nd column..and saved like this and small calculation and initialization var1 =$1 var2 =$2... (5 Replies)
Discussion started by: Akshay Hegde
5 Replies

4. UNIX for Dummies Questions & Answers

What's wrong on this script?

I get this error on these lines when i run this script:"for i in /home;do file2=`ls -s $i` if ;then ls - s $i fi done (7 Replies)
Discussion started by: kotsos13
7 Replies

5. Shell Programming and Scripting

What's wrong with my script ....

Please see below mentioned my script ... it ran once without any issue .... then after it is not coming out .... please suggest what is wrong? #!/bin/ksh ## if (( ${num_errors} > 0 )); export ACULOG=/home/varshnes/input export num_errors=10 **** Search for 'Start correcting roll up... (7 Replies)
Discussion started by: heyitsmeok
7 Replies

6. Shell Programming and Scripting

what is wrong with this script?

Hi I've made a short script but it is not working. Can some pl. help me out in this? ./123.sh #! /usr/bin/ksh # for changing to this directory cd /layered/relational/scripts When I run the above scripts, it doesn't change to the above directory. I don't what is the problem? the... (2 Replies)
Discussion started by: Mike1234
2 Replies

7. UNIX for Dummies Questions & Answers

what is wrong with this script?

Hi, I have this example script which gives error ": unexpected operator/operand". I need the '' brackets for operator precedence. #!/bin/ksh x="abc" y="xyz" z="123" if -a then print "yes" else print "no" fi Thanks (2 Replies)
Discussion started by: rs1969
2 Replies

8. Shell Programming and Scripting

What's wrong with this script

I am trying to create a script but it is giving me errors on Cygwin for the following script. Could someone tell me, what am I doing wrong? choice=1000 echo "choice is $choice" while ; do echo "choice is $choice" echo 'Please select your option:' echo '1. Option 1' echo '2. Option 2'... (3 Replies)
Discussion started by: amitg1980
3 Replies

9. Shell Programming and Scripting

What is wrong with this script?

I keep getting errors messages for the "else" statement at line 81? #!/bin/ksh ######### Environment Setup ######### PATH=/gers/nurev/menu/pub/sbin:/gers/nurev/menu/pub/bin:/gers/nurev/menu/pub/mac :/gers/nurev/menu/adm/sbin:/gers/nurev/menu/adm/bin:/gers/nurev/menu/adm/mac:/ge... (8 Replies)
Discussion started by: heprox
8 Replies

10. UNIX for Dummies Questions & Answers

What is wrong with my script?

Hey guys, can someone help me with this script... #!/bin/sh dir=`pwd` for i in *.f do if then M=`wc -l < ${i} sed -e 's://.*::' < ${i} | \ (echo "//${i} -"$M ; cat - ) > $i.tmp chmod 700 $i ; mv ${i}.tmp $i ... (6 Replies)
Discussion started by: Lem2003
6 Replies
Login or Register to Ask a Question