Sponsored Content
Full Discussion: Error Checking Problem
Top Forums Shell Programming and Scripting Error Checking Problem Post 302088160 by pokeycam on Saturday 9th of September 2006 12:51:17 PM
Old 09-09-2006
I've tried to do it with appending the read of the user to a text file and then reading it back in using grep.

Here is the code below, still not complete.

Code:
#!/bin/sh

$entryType

read text
echo $text > output.txt

case $text in
    [a-zA-Z]*[' '][a-zA-Z]*[' '][0-9]*) entryType='3' ;;
    [a-zA-Z]*[' '][a-zA-Z]*) entryType='4' ;;
    [a-zA-Z]*) entryType='1' ;;
    [0-9]*) entryType='2' ;;
    *) entryType='5';;
esac

if test $entryType -eq 1; then
    if egrep "[a-zA-Z]*" output.txt; then
        grep -i $text teledir.txt || echo "No such entry"
    else
        echo "Invaild name"
    fi
fi

if test $entryType -eq 2; then
    if egrep "[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" output.txt; then
        grep -i $text teledir.txt || echo "No such entry"
    else
        echo "Invaild phone number"
    fi
fi

if test $entryType -eq 3; then
    if egrep "[a-zA-Z]*[' '][a-zA-Z]*[' '][0-9]*" output.txt; then
        grep -i $text teledir.txt || <write to text file> | echo "New
entry $text added"
    else
        echo "Invaild phone number"
    fi
fi


if test $entryType -eq 4; then
    if egrep "[a-zA-Z]*[' '][a-zA-Z]*" output.txt; then
        grep -i $text teledir.txt || echo "No such entry"
    else
        echo "Invaild name"
    fi
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help with error checking

I am creating a script that will automatically use sftp to connect to a site and download a file, extract the tar and then delete the tar file once completed. What I am stuck on is the error checking for this process. Here is the code so far: Now this works for me as is, but i need... (0 Replies)
Discussion started by: xianoth
0 Replies

2. Shell Programming and Scripting

Problem in checking file abort

Hi, I would like to know given executing a file with inputs, I would like to know when does it terminate /abort abnormally. I tried to append an echo $? after executing my program which is in C. However, there is nothing..It shows 0 even though the program actually exit. my command is... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

3. UNIX for Dummies Questions & Answers

Problem in checking space of mount.Please help me

Hi everyone, I am writing a script. As a part of this script, I wanted to check the space of few mounts, If the space usage percentage of the mount crosses over a certain limit then i wanted to display a warning message. The following is the command df -k | awk ' { if (($6 == "/export/temp")... (4 Replies)
Discussion started by: Sheethal
4 Replies

4. Shell Programming and Scripting

Facing problem in checking the directory existence

Hi All, I have a written a scell script which checks the existence of a directory. The dierctory name is read from property file. Though the dierctory exists but it says - it does not exist-- Find my code below -- #! /bin/ksh #Tibco Properties file is inclusion .... (5 Replies)
Discussion started by: supriyabv
5 Replies

5. UNIX for Dummies Questions & Answers

Basic number checking problem

Hello all I am having problems using a bash script to read the input from the user and checking that its a valid number. I only want the user to input a maximum of a 3 number string (321 , 521 , 871 etc.). Anything longer or that includes a chararcter or symbol will display an error message. ... (8 Replies)
Discussion started by: ChrisHoogie
8 Replies

6. Programming

Error Checking

Hey guys i am facing a problem in my sql statement. I am trying to check if there is such a value in the database. Code: string NewMovie = "ww"; string queryText ; queryText = "Select * from movie_info WHERE movie_title = '"+ NewTitle +"'"; ... (1 Reply)
Discussion started by: gregarion
1 Replies

7. Programming

C++ - Problem in asking and checking user's passwd

This is the source code: #include <pwd.h> #include <iostream> #include <string.h> using namespace std; int main() { struct passwd *user; char login="alex", password="qwertyuiop"; if ((user= getpwnam(login)) == NULL) cout << "No such user\n"; else if... (24 Replies)
Discussion started by: hakermania
24 Replies

8. Shell Programming and Scripting

Error checking help.

I am currently wrapping up a assignment for one of my classes. I need help writing some error checking logic. The problems I am having are: keeping track of the records I have deleted and reported it back using echo. I have no idea how to do this. ensuring that line numbers fall... (1 Reply)
Discussion started by: Boltftw
1 Replies

9. Shell Programming and Scripting

Problem with a script for checking the state of a process

Hello Everyone, I have a process that should be always running. Unfortunately, this process is getting down almost every 10 minutes. I want to make a script that verify the state of this process: If the process is up, the script shouldn't do nothing and if it's down he should run it. Can... (3 Replies)
Discussion started by: adilyos
3 Replies

10. Shell Programming and Scripting

Problem with ssh and checking if file exists

Hi All, I am facing a problem while checking for existence of file over ssh ! Basically, i want to ssh and check if file exists.. If file exists return 1. If file does not exits return 0 (or any value) I am using the below code file_avail=`ssh username@host "if ]; then exit 1;... (10 Replies)
Discussion started by: galaxy_rocky
10 Replies
FWRITE(3)								 1								 FWRITE(3)

fwrite - Binary-safe file write

SYNOPSIS
int fwrite (resource $handle, string $string, [int $length]) DESCRIPTION
fwrite(3) writes the contents of $string to the file stream pointed to by $handle. PARAMETERS
o $handle -A file system pointer resource that is typically created using fopen(3). o $string - The string that is to be written. o $length - If the $length argument is given, writing will stop after $length bytes have been written or the end of $string is reached, whichever comes first. Note that if the $length argument is given, then the magic_quotes_runtime configuration option will be ignored and no slashes will be stripped from $string. RETURN VALUES
fwrite(3) returns the number of bytes written, or FALSE on error. NOTES
Note Writing to a network stream may end before the whole string is written. Return value of fwrite(3) may be checked: <?php function fwrite_stream($fp, $string) { for ($written = 0; $written < strlen($string); $written += $fwrite) { $fwrite = fwrite($fp, substr($string, $written)); if ($fwrite === false) { return $written; } } return $written; } ?> Note On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen(3) mode parameter. Note If $handle was fopen(3)ed in append mode, fwrite(3)s are atomic (unless the size of $string exceeds the filesystem's block size, on some platforms, and as long as the file is on a local filesystem). That is, there is no need to flock(3) a resource before calling fwrite(3); all of the data will be written without interruption. Note If writing twice to the file pointer, then the data will be appended to the end of the file content: <?php $fp = fopen('data.txt', 'w'); fwrite($fp, '1'); fwrite($fp, '23'); fclose($fp); // the content of 'data.txt' is now 123 and not 23! ?> EXAMPLES
Example #1 A simple fwrite(3) example <?php $filename = 'test.txt'; $somecontent = "Add this to the file "; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> SEE ALSO
fread(3), fopen(3), fsockopen(3), popen(3), file_get_contents(3). PHP Documentation Group FWRITE(3)
All times are GMT -4. The time now is 11:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy