08-20-2007
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?
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am trying to set up a variable based on the name of the file.
function script_name {
if
then
job_name='MONITOR'
return job_name;
elsif
then
job_name='VERSION'
return job_name
fi
}
for i in `ls *log`
do
script_name $i
done. (4 Replies)
Discussion started by: oracle8
4 Replies
2. Shell Programming and Scripting
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
3. Shell Programming and Scripting
hi
i have a file, i am reading line by line and checking a line contains a string ,
`grep "Change state" $LINE`
if
then
echo "The line contains---"
else
echo "The line does not contains---"
i need to check the return code , but i am getting an error
... (4 Replies)
Discussion started by: Satyak
4 Replies
4. Shell Programming and Scripting
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
5. Programming
hi friends ,
i need c code for my app,
in my app the user can create the new user for the system,
while creating the new user ,i try to include the condition
the user name is not present in password.
my exe requrment is : the user name char is not present in password,if the password... (6 Replies)
Discussion started by: vasu28
6 Replies
6. Shell Programming and Scripting
i was just wondering how would you check , beside the lock method, if an instance of another code is already running and if it is then output a message to the user saying the program is already running and exit!! the code is in BOURNE SHELLL!!!
thanks in advance!! (3 Replies)
Discussion started by: bshell_1214
3 Replies
7. Shell Programming and Scripting
I have a short line of code that checks very rudimentary for duplicate code:
sort myfile.cpp | uniq -c | grep -v "^.*1 " | grep -v "}"
It sorts the file, counts occurrences of each line, removes single occurrences and removes the ubiquitous closing brace. The language is C++, but is easily... (3 Replies)
Discussion started by: figaro
3 Replies
8. Shell Programming and Scripting
#!/bin/ksh
#This script will check status of load balancer in AIX servers from hopbox
#Steps to do as folows :
#Login to server
#netstat -ani | grep <IP>
#check if the output contains either lo0 OR en0
#if the above condition matches, validation looks good
#else, send an email with impacted... (7 Replies)
Discussion started by: vinil
7 Replies
9. UNIX for Beginners Questions & Answers
Hi,
I am writing the shell script in ksh to check certain no of files exists,In my case there are 7 files exist like below
Sales1_timstamp.csv
Sales2_timstamp.csv
Sales3_timstamp.csv
Sales4_timstamp.csv
Sales5_timstamp.csv
Sales7_timstamp.csv
Sales7_timstamp.csv
Once all the files... (4 Replies)
Discussion started by: SRPR
4 Replies
mkdir(1) General Commands Manual mkdir(1)
NAME
mkdir - Makes a directory
SYNOPSIS
mkdir [-m mode] [-p] directory...
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
mkdir: XCU5.0
Refer to the standards(5) reference page for more information about industry standards and associated tags.
OPTIONS
Sets the file permissions to mode, a symbolic mode string as defined for chmod, after creating the specified directory. The mode argument
can be either an absolute mode string or a symbolic mode string as defined for chmod. See the chmod(1) reference page.
In symbolic mode strings, the operation characters + and - are interpreted relative to an assumed initial mode of a=rwx, A + adds
permissions to the default mode, whereas a - deletes permissions from the default mode. Creates intermediate directories as neces-
sary; otherwise, the full path name prefix to directory must already exist. The user must have mkdir write permission in the parent
directory.
Each component of directory that does not name an existing directory is created with mode 777, modified by the current file mode
creation mask (umask). The equivalent of chmod u+wx is performed on each component to ensure that mkdir can create lower directo-
ries regardless of the setting of umask. Each component of directory that names an existing directory is ignored without error. If
an intermediate path name component exists, but permissions are set to prevent writing or searching, mkdir fails and returns an
error message. The mode argument does not apply to any intermediate directories created when the -p option is specified.
OPERANDS
The path name of the directory to be created.
DESCRIPTION
The mkdir command creates new directories with read, write, and execute permissions based upon the permissions established by the umask
setting.
[Tru64 UNIX] The mkdir command also creates the standard entries (dot) for the directory itself and (dot dot) for its parent.
NOTES
Some of the requested directories may be created although an error occurs subsequent to the directory creation. If the directory specified
by the -p option already exists, the command does not return an error status, in compliance with POSIX.2. [Tru64 UNIX] To make a new
directory, you must have write permission in the parent directory.
EXIT STATUS
The following exit values are returned: All requested directories were created, or the -p option was used and all of the requested directo-
ries now exist. An error occurred.
EXAMPLES
To create a new directory called test, enter: mkdir test To set file permissions for new directory test in absolute mode, enter: mkdir -m
444 test To set file permissions for new directory test in symbolic mode, enter: mkdir -m+rw test
ENVIRONMENT VARIABLES
The following environment variables affect the execution of mkdir: Provides a default value for the internationalization variables that are
unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari-
ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value,
overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes
of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale for the for-
mat and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of
LC_MESSAGES.
SEE ALSO
Commands: chmod(1), rm(1), rmdir(1), Bourne shell sh(1b), POSIX shell sh(1p), umask(1)
Functions: mkdir(2)
Standards: standards(5)
mkdir(1)