bash error checking problems[solved]

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions bash error checking problems[solved]
# 1  
Old 10-12-2012
bash error checking problems[solved]

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data: I am trying to make a script called showtime that displays the current time for a given city.
The problem is on the error checking part im trying to make the script search a directory called zoneinfo to see if the region or city the user entered exist.
2. Relevant commands, code, scripts, algorithms:
# Declear Varables
region=$1
city=$2
#Checking if region exist in the database
region=$(ls ~/zoneinfo| grep '$1')


3. The attempts at a solution (include all code and scripts):
# Declear Varables
region=$1
city=$2
#Checking if region exist in the database
region=$(ls ~/zoneinfo| grep '$1')

if [ '$1' == "" ]; then
echo $1 does not exist
exit 2
fi



4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):Seneca College professor name John selmy/course name OPS 435

your website wont let me post the url to the courses sit for some reason??


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by vbe; 10-12-2012 at 06:03 AM..
# 2  
Old 10-12-2012
use double quotes, while using the grep

Code:
 
$ a=TEST
$ echo "TEST" | grep '$a'   #it will not give output
$ echo "TEST" | grep "$a" 
TEST

# 3  
Old 10-12-2012
I tried that but it won't display the error message to the user

heres my code now
Code:
#Checking if region exist in the database
region=$(ls zoneinfo| grep "$1")
echo $region
if [[ $1 = "" ]]; then
    echo $1 does not exist
    exit 2
fi

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by vbe; 10-12-2012 at 12:03 PM..
# 4  
Old 10-12-2012
Just teasing a bit...
What if you change directory ( see me coming?...)
what would be the output of region=$(ls zoneinfo| grep "$1")?

...
assuming zoneinfo is in $HOME:
Code:
region=$(cat ~/zoneinfo | grep "$1")
echo $region
if [ "$region" = "" ]
then
    echo $1 does not exist
    exit 2
fi


Last edited by vbe; 10-12-2012 at 12:39 PM..
# 5  
Old 10-12-2012
Code:
region=$(ls ~/zoneinfo|grep $1| cut -d"/" -f1 )

with that block of code im trying to make the script search for a region that a user entered which is $1 and see if the region that user entered exists or not

Code:
if [[ "$1" = "" ]]; then
    echo $1 does not exist
    exit 2
fi

but when I run my script showtime with a wrong region it does not show the error message.

Last edited by Corona688; 10-15-2012 at 12:36 PM..
# 6  
Old 10-15-2012
Code:
ant:/home/vbe/test $ zz Autralia 

Autralia does not exist
ant:/home/vbe/test $ zz Australia
Australia
ant:/home/vbe/test $ more zz
#region=$(cat zoneinfo | grep "$1") # Now I understood what you are up to
region=$(ls ~/zoneinfo|grep $1| cut -d"/" -f1)   # ln -s to zoneinfo directory...in $HOME
echo $region
if [ "$region" = "" ]
then
    echo $1 does not exist
    exit 2
fi

zz: END

$1 empty for me means nothing was entered... You say in your last post you are looking for a region...
# 7  
Old 10-17-2012
nvm i fixed the problem last week Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash : Checking Large file for specific lines

Morning .. I have a file with approximately 1000 lines. I want to check that the file contains, for example, 100 lines. Something like whats given below is ugly. And even if I create a function I have to call it 100 times. I may need to look through multiple files at times. Is there a... (4 Replies)
Discussion started by: sumguy
4 Replies

2. Shell Programming and Scripting

checking first argument for tag in bash script

I have a bash script where I pass an argument ./chris.bash "\argv Test" I want to detect if the user supplied \argv at the start of the argument (3 Replies)
Discussion started by: kristinu
3 Replies

3. Shell Programming and Scripting

Multiple condition checking in bash

Hi All, I am trying to check if two variables have value assigned to it. i am doing it like if ] then echo "Please specify either single hostname or host file for the report" usage exit fi But its not working for it.Even i specify values for both variables it dont go... (6 Replies)
Discussion started by: kailash19
6 Replies

4. HP-UX

Solved -- Problems with NIS Password Expiration...

HI. I was wondering if anyone can assist me in this. I have an HP-UX 11.31 server at work which keeps expiring my NIS password. I cannot log in unless I use root access. It worked before and I think some of the settings changed since then. My boss has told me that since we're taking some... (1 Reply)
Discussion started by: zixzix01
1 Replies

5. AIX

problems connecting with exceed (solved)

Hi, We have a user who cannot connect to the aix system anymore with hummingbird exceed. Our unix servers are aix 5.3. She is running windows xp and using hummingbird 12. She used to not have any problem, but now when she tries to use xstart she gets an error 'unable to connect to host using... (0 Replies)
Discussion started by: fwellers
0 Replies

6. Shell Programming and Scripting

[Solved] <<EOF error checking

I am trying to check the return status of a command thats encapsulated in an <<EOF #!/bin/ksh set -x xxx() { set -x ls -lt /tmp/jdlkewjdlkewjdlkewjdlewjdlew<<EOT ret=$? EOT echo "ret=$ret" } >>$LOG 2>&1 LOG=/tmp/t2.out rm -rf $LOG echo "Starting process `date... (2 Replies)
Discussion started by: BeefStu
2 Replies

7. Shell Programming and Scripting

bash: checking file size -solved

Hello I have srv RHEL5, file system UTDM (EMC DiskXtender Unix/Linux File System Manager 3.5 & EMC Centera). it all works under the scheme: have disk is formatted with a file system UTDM, drive open network - NFS, it write data, then migrate the data in the repository - EMC Centera. There are... (0 Replies)
Discussion started by: moskovets
0 Replies

8. Shell Programming and Scripting

bash if loop for checking multiple parameters

Hello, I've got next problem: I want to examine at the beginning of a script in an if loop that: 1. Is there 4 parameters given 2. If first state is true then: is there switches -e and -d? 3. At the end, how can i indentify them as variebles regardlees to its order. I was thinking like... (2 Replies)
Discussion started by: szittyafergeteg
2 Replies

9. UNIX and Linux Applications

Kudda has successfully solved the downloading problems for numerous video web

The rise of Video web stimulates more intuitive video feeling of large people, and makes video downloading becomes a popular trend in web times, meanwhile, more and more downloading problems arises correspondingly, in which the first trouble is slow downloading speed and incomplete downloading. It... (0 Replies)
Discussion started by: angelstar
0 Replies

10. Shell Programming and Scripting

error checking in bash

Could someone please advise on a good way to implement error checking in a script? i am taking input from a file, iserting it's values into two commands and sending the output of each to seperate log files. i need to check those log files for for an occurance of 'error', stop the command if... (3 Replies)
Discussion started by: gubten
3 Replies
Login or Register to Ask a Question