The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
some information on error checking vinayrao Shell Programming and Scripting 1 03-14-2008 12:07 PM
Need help with error checking xianoth Shell Programming and Scripting 0 08-31-2007 12:47 PM
Error Checking Problem pokeycam Shell Programming and Scripting 4 09-13-2006 04:38 AM
error checking in bash gubten Shell Programming and Scripting 3 06-06-2006 05:38 PM
Code checking for all values in the same if statement. oracle8 Shell Programming and Scripting 4 01-23-2004 09:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-20-2007
jepombar jepombar is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 5
Error code checking

I'm trying to create a directory from my Perl script. Only if the there was an error I want to let the user know about it. So if the folder exists is ok.

This is what I think should work:

`mkdir log 2>/dev/null`;
if($? == 0 || $? == errorCodeForFileExists)
{ everyting is fine }
else
{ print "Error creating log directory. Check you file permissions\n";
exit(0) }

The problem is that I'm getting the same error code for both File exists and Permission Denied.

Any ideas?
  #2 (permalink)  
Old 08-21-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
I am not clear about your requirement, but i guess this is what you are looking for.


Code:

mkdir foldername
if [[ -d foldername ]]; then

echo "The folder Exists and everything is fine"
else

echo "ERROR"
fi

  #3 (permalink)  
Old 08-21-2007
jepombar jepombar is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 5
I'm doing it in perl

Sorry if I wasn't clear.
I need to create a folder and if there is any errors like permission errors I want to let the user know about it. However I don't wish to overwrite the folder if it already exists. Also I need to do it inside a Perl script.

This is the workaround I came up with:

`ls log 2> /dev/null`; #check if the folder exists
if($?) { #if it doesn't create it
`mkdir log`;
$dirFlag = 1; #flag to know that dir was created
}

The bad thing about this is that it wont let the user know if there were any permission errors. In other words, if the folder wasn't created for some reason the program will crash later when I try to write to that folder.

So what I want to do is to somehow check, in my Perl code, the error code that UNIX spits out. The problem is that I'm getting the same error code number for both "File Permission" and "File exists" errors.
  #4 (permalink)  
Old 08-21-2007
jepombar jepombar is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 5
Got it

I just found a tutorial on manipulating files and directories and I got my answers. Thanks.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0