Avoid Common Errors in UNIX and Linux

Source: Internet
Author: User
To avoid common errors in UNIX and Linux-Linux general technology-Linux technology and application information, read the following for details. Have you ever encountered an error message like Execute permission denied or The parameter list is too long? Do you want to know the cause of the error? These are common errors for beginners of UNIX and Linux. They may not know how to avoid these problems. This article explains these errors and provides solutions.

./Foo: 0403-006 Execute permission denied.

You have written or downloaded a new shell script and want to try it. This sounds good, but when trying to Execute this command, I received an error message./foo: 0403-006 Execute permission denied. Why? This message may result from two problems:

You do not have sufficient permissions to execute this command.
You do not have sufficient permissions for the shell defined in the script and cannot tell the shell how to interpret the script and the commands in it.
You do not have sufficient permissions to execute this command

The easiest way to check permissions is to check which user you log on to the server and then view ls? L output:

# Id
Uid = 5008 (Cortana) gid = 330 (atc) groups = 110 (sales), 201 (sshd)

# Ls-l foo
-Rwxrw-r -- 1 Cortana atc 75 Jun 10 18:46 foo



Based on this example, you log on as the user Cortana, and the shell script owner is Cortana, which has the rwx permission (read, write, and execute ). This is okay, so we will consider the next possible reason.

You do not have sufficient permissions for the shell defined in the script and cannot tell the shell how to explain the script and the commands in it.

Let's take a look at the script:

# Cat foo

#! /Bin/ksh. new

Echo "This is a just a test"

Exit 0



According to the first line, this script should be interpreted as the Korn shell script. By checking the shell Permission, you can check whether it can be used:

# Ls? L/bin/ksh. new

-R-xr-x --- 5 bin 289072 May 27/bin/ksh. new



As the root user, modify the File Permission of the shell to be used and try again:

Switch to the root user: # su-
Root's Password:



Make sure that you are a root user instead of the original user: # id
Uid = 0 (root) gid = 0 (system) groups = 2 (bin), 3 (sys), 7 (security), 8 (cron), 10 (audit ), 11 (lp)



Modify file permissions: # chmod 555/bin/ksh. new



Confirm that the File Permission has changed: # ls-l/bin/ksh. new
-R-xr-x 1 bin 289072 Jun 10/bin/ksh. new



Log out of su and restore to the original user: # exit
# Id
Uid = 5008 (Cortana) gid = 330 (atc) groups = 110 (sales), 201 (sshd)



Run the script again: #./foo
This is a just a test



Okay, the problem is solved!






Back to Top




Ksh: bar: not found.

You have written another script bar and saved it in ~ In the Cortana/scripts directory. When using the full path or in the current working directory (~ It works normally when executing this script in Cortana/scripts). However, for some reason, if you only enter the Script Name in another directory, you cannot run it:

# Pwd
/Home/Cortana/scripts

#/Home/Cortana/scripts/bar
This is another test

#./Bar
This is another test

# Cd

# Pwd
/Home/Cortana

# Bar
Ksh: bar: not found.



Everything works, but the script cannot be run from another directory. There are three common error messages:

You do not have permission for the files you are trying to execute.
The file does not exist or is not in the directory you think.
The file exists and is expected. You have sufficient permissions for the file.
You are not authorized to execute the file

You know this is not the reason, because the script can be executed when a fully qualified path is provided or in the command directory. If this possibility cannot be ruled out, checking the File Permission should help identify the cause of the problem:

# Ls-la ~ Cortana/scripts
Total 56
Drwxr-xr-x 2 Cortana atc 512 Jun 12.
Drwxr-xr-x 6 Cortana atc 512 Jun 10 ..
-Rwxr-xr-x 1 Cortana atc 42 Sep 06 16:20 amdc
-Rw-1 Cortana atc 154 Jan 27 atc
-Rwxr-xr-x 1 Cortana atc 206 Aug 04 20:57 atc.2
-Rwxr-xr-x 1 Cortana atc 48 Jun 12 bar
-Rwxr-xr-x 1 Cortana atc 87 Feb 22 pac



Execute ~ The Cortana/scripts/atc command fails because the file only has read and write permissions for users, groups, and other users. You only need to add execution permissions to solve this problem.

If you cannot execute another command in another directory (for example ~ Cortana/scripts. old/cujo), you should also check the permissions of that file:

# Ls-l ~ Cortana/other_scripts/cujo
Ls: 0653-345/home/Cortana/other_scripts/cujo: Permission denied.



At first glance, you do not even have the read permission. Let's take a look at the target directory and see what happened:

# Cd ~ Cortana/scripts. old/cujo
Ksh:/home/Cortana/other_scripts: Permission denied.

# Ls-l ~ Cortana/scripts. old/cujo
Ls:/home/Cortana/scripts. old: The file access permissions do
Not allow the specified action.
Total 0



What happened here? This is another form of permission error. Permission errors may not always occur in the file itself, but also in the directory in the file path:

# Ls-ld ~ Cortana/scripts. old
D --------- 2 Cortana atc 512 Jan 22/home/Cortana/scripts. old



If the file itself has sufficient permissions, correcting the permissions on the directory path should solve the execution problem:

# Chmod 755 ~ Cortana/other_scripts
# Cd ~ Cortana/other_scripts
# Ls? L cujo
-Rwxr-xr-x 1 Cortana atc 48 Jan 26 cujo



Now, go back to the original ~ Cortana/scripts/bar.

The file does not exist or is not in the directory you think

Similarly, if you run the ls command to perform a quick check, you should see whether the file exists:

# Ls-l ~ Cortana/scripts/bar
-Rwxr-xr-x 1 Cortana atc 48 Oct 05/home/Cortana/scripts/bar



If this file is not found in your original directory, you will receive the following message:

# Ls-l ~ Cortana/scripts/bar
Ls: 0653-341 The file/home/Cortana/scripts/bar does not exist.



If you think this file is somewhere else in the user's Cortana home directory, you can use the find command to search for it (if you have sufficient permissions ):

# Find ~ Cortana-name "bar"-ls
16409 1-rwxr-xr-x 1 Cortana atc 48 Sep 06 08:06/home/Cortana/atc/bar
590040 1-rwxr-xr-x 1 Cortana atc 48 Sep 09/home/Cortana/test/bar



The file exists and is in the expected location. You have sufficient permissions for the file.

The method used for successful execution is to provide a fully qualified command path, or enter the current working directory (that is, use./) in the command directory ./). Since it is not in the command directory and does not enter the complete PATH, let's check the value of the PATH environment variable:

# Echo $ {PATH}
/Usr/bin:/etc:/usr/sbin:/usr/ucb:/bin:/usr/bin/X11:/sbin:/usr/
Java5/jre/bin:/usr/java5/bin:/usr/ushare/bin:/usr/local/bin



The directory/home/Cortana/scripts is not in the path. There are two ways to correct this problem:

Add ~ In PATH ~ Cortana/scripts. Although this modification is easy to execute, remember that every time you add a directory to the PATH variable, shell will search for another directory when searching for commands. If 10 directories are added over time, it needs to search 10 more Directories Before the shell returns the results of the file that cannot be found. To do this, run the following command: # export PATH =$ {PATH}:/home/Cortana/scripts
# Echo $ PATH
/Usr/bin:/etc:/usr/sbin:/usr/ucb:/bin:/usr/bin/X11:/sbin:/usr/
Java5/jre/bin:/usr/java5/bin:/usr/ushare/bin:/usr/local/bin :/
Home/Cortana/scripts



Note: It is usually unwise to add a PATH to the beginning of your PATH variable. This may cause the execution of unnecessary commands. If you think you must put a path at the beginning, be cautious.

Transfers (or copies) the script to an existing directory in the PATH variable. This solution is better if multiple users may use this script. In this case, users usually put their files in/usr/local/bin.





Back to Top




Ls: 0653-341 The file. does not exist.

You are ~ Works in the Cortana/scripts directory. Suddenly, the scripts in this directory cannot be found. You receive a strange message saying that the current working directory no longer exists:

# Ls-l
Total 40
-Rwxr-xr-x 1 Cortana atc 42 Sep 06 16:20 amdc
-Rw-1 Cortana atc 154 Jan 27 atc
-Rwxr-xr-x 1 Cortana atc 206 Aug 04 20:57 atc.2
-Rwxr-xr-x 1 Cortana atc 48 Jun 12 bar
-Rwxr-xr-x 1 Cortana atc 87 Feb 22 pac

#./Bar
This is another test

# Pwd
/Home/Cortana/scripts

#./Bar
Ksh:./bar: not found.

# Ls-l
Ls: 0653-341 The file. does not exist.



In this case, the original working directory is deleted using the rm command. Creating a new directory with the same name does not solve this problem because the file descriptor is different.

This is often because you execute the rm command in another window (at least I do ). To avoid this problem, you can run the mv command to modify the directory name. If you modify the directory name, users in the original directory can continue to work, but use different directory names, because the file descriptor is still the same:

# Ls-l
Total 40
-Rwxr-xr-x 1 Cortana atc 42 Sep 06 16:20 amdc
-Rw-1 Cortana atc 154 Jan 27 atc
-Rwxr-xr-x 1 Cortana atc 206 Aug 04 20:57 atc.2
-Rwxr-xr-x 1 Cortana atc 48 Jun 12 bar
-Rwxr-xr-x 1 Cortana atc 87 Feb 22 pac

#./Bar
This is another test

# Pwd
/Home/Cortana/scripts



Similarly, assume that someone changes the directory you are working on in another session ~ Cortana/scripts.20090601. Because you only want to transfer the Directory and modify the directory name, you can continue to work:

#./Bar
This is another test

# Pwd
/Home/Cortana/scripts.20090601







Back to Top




./Foo:/usr/bin/ls: 0403-027 The parameter list is too long.

A program in your IBM®AIX®It has been running on the computer for several months and no problem has occurred. However, when the program runs, it creates files in the same log directory every few minutes. The file name is f. And e. . The directory is getting full, and the response time of the ls command increases significantly. This is understandable because there are too many files in the directory.

After a few months, the AIX program has been running and there is still no problem. Now, there are 100,000 files starting with f. And the other 100,000 files starting with e. Now, if you try to clear this log directory and delete a file starting with f., you will receive the following message:

# Rm ~ Cortana/logs/f .*
Ksh:/usr/bin/rm: 0403-027 The parameter list is too long.



I think you haven't cleared the file for too long. However, it's not too late.

When executing commands such as delete, all parameters are checked and expanded before execution. Search for this example ~ Cortana/logs/f. *, which is the 100,000 parameter of the rm command. In other words, the actual execution is not rm ~ Cortana/logs/f. *, rather than rm ~ Cortana/logs/f.1 ~ Cortana/logs/f.2 ~ Cortana/logs/f.3... ~ Cortana/logs/f.100000.

Like other UNIX and Linux operating systems, AIX specifies the length of command line parameters and environment variables that can be used. In AIX, you can use the getconf command to check this value. On the getconf manual page, you will see ARG_MAX:

# Man getconf
...
ARG_MAX
Maximum length, in bytes, of the arguments for one of the exec
Subroutines, including environment data.
...
# Getconf ARG_MAX
1048576



This value indicates that the environment variables and command line parameters can be 1,048,576 bytes. It seems that you have exceeded this limit. There are two ways to solve this problem:

Use smitty chgsys and modify ARG/ENV list size in 4 K byte blocks to increase the value, or use chdev to increase the value. I do not recommend that you modify the system range parameters for the convenience of the diagram every time you encounter such errors: this should be the last move.
Instead of using the rm command with 100,000 parameters (this will fail to be executed), you can use the find command to delete the file, which is much better: # find ~ Cortana/logs? Name "f .*"? Exec rm {}\;



The find command searches for all files starting with f. in the directory, instead of placing so many parameters in the shell command line. Then, run the find command to execute rm for each found file, which will delete all files starting with f.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.