Self referencing script error message


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Self referencing script error message
# 1  
Old 01-31-2011
Self referencing script error message

Hello again all. I have a user editable script that I'd like to have point out the user error to. Problem is I'm having troubles getting an echoed error message to give me the line. Here's what I'm trying to do.
Code:
 grep -n $loc /this/script.sh

where '$loc' is the argument passed to the script. Here's the USAGE: for the script:
Code:
./makeBackup /var/directory/toBackup/

The argument is stored as '$loc'. I want to echo " '$loc' is not a valid directory (grep'd location of error)" If I'm not being clear forgive me it's kinda early here. But basically I need to alert the user of the line number where they made their mistake in the error message.
# 2  
Old 01-31-2011
So from the script you already test whether the directory passed is valid, and if it's not, you want to spit out something like "usage: ./makeBackup /path/to/dir: Not valid" or something similar?

the following works in sh/bash, ksh.

Code:
echo "usage: $0 ($1 not a valid dir)"

.. can be illustrated in the following scenario:

Code:
$ ./makeBackup /some/nonexistant/dir
usage: ./makeBackup (/some/nonexistant/dir not a valid dir)
$

HTH
# 3  
Old 01-31-2011
Thanks for your response man I appreciate it. I can get that part of the error just fine but I want to reference the line number they made their mistake. See, in the script you put the directories you want to backup in the script itself. Instead of doing it for each and every directory from the command line, you simply put 'makeBackup /var/this/dirExists'. If that dir does not exist, I'd like the error message to reflect its not a valid location and then give the line number where they made their mistake. So if i grep that script I can see the line number if I use -n. I want that to be echo'd back to the user
# 4  
Old 01-31-2011
As you said it's not clear enough..Smilie However im assuming this what your looking for..
Code:
loc=$1 # Stores the 1st argument to variable loc - /var/directory/toBackup/
echo "$(grep -n "$loc" /this/script.sh)  is not a valid directory"

# 5  
Old 01-31-2011
Yea man sorry...totally not clear, that did the trick tho. Just one problem, I'd like the script to know where its at. So no matter which directory it's run from it can grep -n itself to find that error. I don't want a hardcoded path to it in the script.
# 6  
Old 01-31-2011
How can you find where error occurs while the passed parameter isn't hardcoded in the script?
# 7  
Old 01-31-2011
The parameter is hardcoded. I don't want the path to the script to be hardcoded as I want it to be able to reference itself no matter which directory it's in. The '$loc' parameter is hardcoded. That's the error I need it to spit out if '$loc' wasn't valid.

I want the error to say "You specified a target that wasn't valid and here's the line number of that invalid target" basically. The script needs to be able to do that no matter if it's in /var/root or /var/foo/bar/lorem/ipsum/dolor/we/are/the/world/we/are/the/children/
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script error message

I have this UNIX script code with a query to export sql table in Oracle and export to csv file. The code gets the data correctly. However, when I run the script second time, I got the error message "not spooling currently" and shows the older data in csv file. When I delete the csv file and run... (5 Replies)
Discussion started by: Hope
5 Replies

2. UNIX for Beginners Questions & Answers

UNIX script error message

Greeting!! I wrote the below script to e-mail me only file names in a specific directory when a file is delayed for some time in a that directory. I am getting unexpected eof error message. I don't want any email if the folder is blank.(if the condition is not met) I am not getting the email at... (4 Replies)
Discussion started by: Hope
4 Replies

3. Shell Programming and Scripting

How to deliver an error message from script?

Hi I have a script that pick up a file on another server, and place it on a solaris server, but I came across the following error: mget HLR01_21092014? 200 Port command successful 150 Opening data channel for file transfer. HLR01_21092014: No space left on device 426 Connection closed;... (18 Replies)
Discussion started by: fretagi
18 Replies

4. Shell Programming and Scripting

Passing error message back to script

I have one script that calls another script during execution. The other script does some processing, then either returns with exit 0 (if successful), or exits with error code numbers (if failed). However, in addition to the error code, I would like for that second script to be able to pass a... (4 Replies)
Discussion started by: AcerAspirant
4 Replies

5. Shell Programming and Scripting

Shell Script Referencing I/O

Is it possible to design a shell script to reference something that queries for input? (This is not to make a script to ssh) For instance if I have a command that when run, it does something like: %<Some command> User's password? Would it be possible to write a script to input something... (1 Reply)
Discussion started by: Prodiga1
1 Replies

6. Programming

Symbol referencing error

Hey everyone, I can't figure out this symbol referencing error after looking at it for the longest time, and I figured some fresh eyes might be able to point something out I am overlooking. Undefined first referenced symbol in... (1 Reply)
Discussion started by: fromatz
1 Replies

7. Shell Programming and Scripting

Suppress error message in shell script

Hi All this is a simple script #! /bin/bash FileCnt=`ls -lrt $DIR/* | wc -l` echo $FileCnt how could i escape the error msg if there are no files in $DIR ls: /home/sayantan/test/files/cnt/*: No such file or directory 0 Looking forward for a quick reply Regards, Newbie... (3 Replies)
Discussion started by: newbie07
3 Replies

8. Shell Programming and Scripting

Error message while executing the shell script

Hi All, When I am trying to execute the below shell script I got this error message. script ========== #!/bin/bash /usr/java/jdk1.5.0_10/bin/java - classpath /var/lib/asterisk/agi-bin/mysql-connector-java-3.0.15-ga-bin.jar/: /var/lib/asterisk/agi-bin/jarfiles:... (4 Replies)
Discussion started by: ajayyaduwanshi
4 Replies

9. Programming

symbol referencing error

Undefined first referenced symbol in file std::basic_ostream<char, std::char_traits<char> >::operator<<(int)/var/tmp//ccTR std::cerr /var/tmp//ccTRcjui.o std::cout /var/tmp//ccTRcjui.o... (1 Reply)
Discussion started by: suhasini
1 Replies

10. Shell Programming and Scripting

problem with script and syntax error message

Hi I have the following script and have problem debugging the problems. The function of this script is to make sure the entire file is being received (the filesize of a data is not changing after 20 seconds) and start moving the file to another directory. This script should be started every 30mins.... (5 Replies)
Discussion started by: ReV
5 Replies
Login or Register to Ask a Question