Sponsored Content
Full Discussion: Script Gone Wrong
Top Forums Shell Programming and Scripting Script Gone Wrong Post 302421593 by ibzee33 on Saturday 15th of May 2010 02:00:28 AM
Old 05-15-2010
Script Gone Wrong

Hello all,

so this is a script i did for an assignement,
- first option greets the user according to the time after fetching his name
- second options isn't implemented
- third check the performance according to how many users are using the system
- creates a log of names, time and ip of the user currently using the system.

problem is the script was working at some point, or so id like to believe.
after a few days i tried to run it, and i got syntax error on every option.
i tried looking over at it, but it seems right.

so im hoping someone would be able to figure out happened to it!!


Code:
echo Choose Number to select:
echo 1.Greet User
echo 2.Replace Patter
echo 3.Check Performance
echo 4.Log info
echo 5.Exit

read choice

user=$(whoami | cut -d" " -f1 )
name=$(grep $user /etc/passwd | cut -d: -f5)

while [ $choice -ne 5 ]
do
    if [ $choice -eq 1 ]
    then
        time=$(date | cut -d" " -f5 | cut -d: -f1)
        if [ $time -gt 00 -a $time -le 12 ]
        then
            echo Good Morning $name
        elif [ $time -gt 12 -a $time -le 17 ]
        then
            echo Good Afternoon $name
        elif [ $time -gt 17 -a $time -le 24 ]
        then
            echo Good Evening $name
        fi
    elif [ $choice -eq 2 ]
    then
        echo $choice
    elif [ $choice -eq 3 ]
    then
        users=$(uptime | cut -d" " -f8)
        if [ $users -ge 0 -a $users -lt 7 ]
        then
            echo System has high performance
        elif [ $users -ge 7 -a $users -lt 12 ]
        then
            echo System has medium preformance
        elif [ $users -gt 12 ]
        then
            echo System has low performance
        fi
    elif [ $choice -eq 4 ]
    then
        who > temp
        lines=$(wc -l ./temp | cut -d" " -f1)
        cnt=1
        
        touch tmplog    
        touch logfile

        while [ $cnt -le $lines ]
        do
            usertemp=$(head -$cnt ./temp | tail -1 | cut -d" " -f1)
            nametemp=$(grep $usertemp /etc/passwd | cut -d: -f5)
            datetemp=$(head -$cnt ./temp | tail -1 | cut -d" " -f13)
            adrstemp=$(head -$cnt ./temp | tail -1 | cut -d" " -f14)

            if [ "$usertemp" != "$user" ]
            then 
                echo -n $nametemp >> tmplog
                echo -n " " >> tmplog
                echo -n $datetemp >> tmplog
                echo -n " " >> tmplog
                echo -n $adrstemp >> tmplog
                echo "" >> tmplog
            fi
            timetemp=$(head -$cnt ./temp | tail -1 | cut -d" " -f1)
            let cnt=$cnt+1             
        done        
        
        sort -db tmplog -o logfile
        rm temp
        rm tmplog
    else
        echo no such option

    fi

echo Choose Number to select:
echo 1.Greet User
echo 2.Replace Patter
echo 3.Check Performance
echo 4.Log info
echo 5.Exit

read choice

done

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
SCRIPT(1)						    BSD General Commands Manual 						 SCRIPT(1)

NAME
script -- make typescript of terminal session SYNOPSIS
script [-a] [-c COMMAND] [-f] [-q] [-t] [file] DESCRIPTION
Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript. Options: -a Append the output to file or typescript, retaining the prior contents. -c COMMAND Run the COMMAND rather than an interactive shell. This makes it easy for a script to capture the output of a program that behaves differently when its stdout is not a tty. -f Flush output after each write. This is nice for telecooperation: One person does `mkfifo foo; script -f foo' and another can super- vise real-time what is being done using `cat foo'. -q Be quiet. -t Output timing data to standard error. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays. The script ends when the forked shell exits (a control-D to exit the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not set) for the C-shell, csh(1)). Certain interactive commands, such as vi(1), create garbage in the typescript file. Script works best with commands that do not manipulate the screen, the results are meant to emulate a hardcopy terminal. ENVIRONMENT
The following environment variable is utilized by script: SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most shells set this variable automatically). SEE ALSO
csh(1) (for the history mechanism), scriptreplay(1). HISTORY
The script command appeared in 3.0BSD. BUGS
Script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects. AVAILABILITY
The script command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/. Linux July 30, 2000 Linux
All times are GMT -4. The time now is 10:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy