LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   command not found error while executing a shell script (http://www.linuxquestions.org/questions/linux-newbie-8/command-not-found-error-while-executing-a-shell-script-822083/)

SurbhiJain 07-25-2010 02:47 PM

command not found error while executing a shell script
 
Hello,

I am a newbie to linux.I am attaching the code which gives me following errors..

error list:

1. no such file or directory enviornemnt
2. command not found
3. ambiguous redirectline

Script

cd $HOME/wkdir

#
#
#

rm /tmp/*.log


#
# source environment
#
. ./env

#
# Run the install script to setup the database
#
#
# Configure SH account
#
sqlplus "/ as sysdba" <<! > /tmp/perflab_install.log 2>&1

grant connect, resource, dba to SH;
alter user sh account unlock;
!

#
# create the fetch_n_rows procedure
#
sqlplus "$PERFLAB_USER" <<! >> /tmp/perflab_install.log 2>&1

drop index sales_time_bix;
drop index sales_time_idx;
create index sales_time_idx on sales(time_id) compute statistics;

-----------------------------------------------------------------
-- fetch_n_rows: fetches 'n' rows from the specified statement --
-----------------------------------------------------------------
CREATE OR REPLACE PROCEDURE fetch_n_rows(
stmt VARCHAR,
name VARCHAR,
nexec NUMBER := 1,
nrows NUMBER := 0,
debug BOOLEAN := FALSE)
IS
-- Local variables
curs INTEGER := null;
rc INTEGER;
nexec_it INTEGER := 0;
nrows_it INTEGER;
BEGIN

dbms_application_info.set_module('DEMO', name);

WHILE (nexec_it < nexec)
LOOP

curs := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(curs, stmt, DBMS_SQL.NATIVE);
rc := DBMS_SQL.EXECUTE(curs);
nrows_it := 0;

LOOP
IF (dbms_sql.fetch_rows(curs) <= 0 OR (nrows <> 0 AND nrows_it = nrows
))
THEN
EXIT;
ELSE IF (debug = TRUE)
THEN
DBMS_OUTPUT.PUT_LINE(nrows_it);
END IF;
END IF;

nrows_it := nrows_it + 1;

END LOOP;

DBMS_SQL.CLOSE_CURSOR(curs);

nexec_it := nexec_it + 1;

END LOOP;

dbms_application_info.set_module(null, null);

END fetch_n_rows;
/

show errors

!

#
# Start the workload
#
. ./start_workload.sh > /tmp/setup_perflab.log 2>&1

#
# Wait two minutes for workload to get going
#
sleep 120

#
# Modify snapshot interval
#

sqlplus -s /NOLOG <<EOF >> /tmp/setup_perflab.log 2>&1

connect / as sysdba

set head on
set feedback on;
set pagesize 40

rem -- event to allow setting very short Flushing interval
alter session set events '13508 trace name context forever, level 1';

rem -- change INTERVAL setting to 2 minutes
rem -- change RETENTION setting to 6 hours (total of 180 snapshots)
execute dbms_workload_repository.modify_snapshot_settings(interval => 2,-
retention => 360);

EOF

Note : start_workload.sh is also in the same directory..

Any help would be greatly appreciated.

Brains 07-25-2010 04:04 PM

A few things you can/should do:

Edit your profile to include the specific Linux distribution(s) you are using.
Post the command you issued and all that bash spit out.

Using command: ls -l start_workload.sh, bash will tell you who is capable of executing the script. Below is an example of the script if it was executable by all:
Quote:

-rwxrwxrwx 1 me me 896 May 3 13:23 start_workload.sh
The (x)s represent executable. If you as a user (the second set of rwx) do not have the x, you cannot run the script as a user, run it as superuser/root or sudo, or change permissions of the script so a user can run it with command as superuser/root or sudo: chmod 777 start_workload.sh. After changing the permissions as outlined it should look like the example I posted with three sets of rwx and anybody can run the script.

SurbhiJain 07-25-2010 04:43 PM

Thanks for answering. I didnt understand how to edit and change the profile. If you can give the pointers.

I have given the permission by chmod 777

I think the script is executing but spitting out errors. Feel like the environment variables havent been set correctly. Listing the errors which i see

setup_perlab.sh line 12: grant: command not found
setup_perlab.sh line 13 : alter: command not found

Any help is greatly appreciated.

Brains 07-25-2010 04:57 PM

Quote:

grant connect, resource, dba to SH;
alter user sh account unlock;
The lines in the setup_perlab.sh script quoted above are the current problem. Bash does not recognize those two commands. Was this script designed for Linux or some other Unix based operating system like Mac OS X or something?
You may need to provide more information regarding the script, such as the software suite you are trying to configure. Many script errors are a result of out-dated software not configured to work with the latest Linux kernel. But this error relates to un-recognized commands in the script.

After changing permissions of a file, just do the: ls -l start_workload.sh again to see what happened.

EDIT: Often, bash will give the "command not found" error when a script is designed to be run as root and you are running it as a user.

SurbhiJain 07-25-2010 05:32 PM

Those are the sql commands which are trying to configure oracle user 'SH'.

ls -l start_workload.sh command shows :
-rwxrwxrwx 1 oracle oinstall 1075 jul 24 14:00 start_workload.s

The very first statement in the script cd $HOME/wkdir generates and error
no such file or directory cd: /home/oracle/wkdir. Although, when i type
cd $HOME/wkdir at the prompt.It works just fine. It is just when i put them in script it gives me error.

tommylovell 07-25-2010 07:09 PM

Brains, I don't think we know for sure that SurbhiJain is running this from a bash shell. There is no "hash bang" forcing execution by bash.

It looks as if the shell is not recognizing the "here document" inline redirection (the <<!) in the command "sqlplus "/ as sysdba" <<! > /tmp/perflab_install.log 2>&1" (Although the "2>&1" seems to imply bash.)

It's also very suspicious that the shell executing the script does not know the value of the $HOME environmental variable (cd $HOME/wkdir generates and error). Maybe something funky with sudoers?

I did a little experiment on my system, and both bash and ksh support "!" as the here document delimiter.

Code:

[root@athlonz ~]# cat zzz
DATE=`date`
HOST=`uname -n`
cat <<!
Something went horribly wrong with system $HOST
at $DATE
btw, your HOME environmental variable is $HOME
!
[root@athlonz ~]# bash zzz
Something went horribly wrong with system athlonz.tomlovell.com
at Sun Jul 25 18:41:24 EDT 2010
btw, your HOME environmental variable is /root
[root@athlonz ~]# ksh zzz
Something went horribly wrong with system athlonz.tomlovell.com
at Sun Jul 25 18:41:30 EDT 2010
btw, your HOME environmental variable is /root
[root@athlonz ~]# echo $HOME
/root
[root@athlonz ~]#

SurbhiJain, see the 3.6.6 section of http://www.gnu.org/software/bash/manual/bashref.html for an explanation of what the "<<!" does.

It looks as if the shell executing your script does not support <<! for some reason.

Can you tell us what shell you are using. The SHELL environmental variable usually contains the current shell.
Do an 'echo $SHELL' and let us know the output.

Also, how are you executing 'start_workload.sh'? Just typing it on the command line?

If you are using bash, 'bash --version' will tell the version. Maybe it's an bug in bash.

SurbhiJain 07-25-2010 07:25 PM

1 Attachment(s)
hi tommylovell,

I am attaching one file giving the answers of your questions. I am sorry i did not tell the name of the script..it is setup_perflab.sh . $HOME variable points to /home/oracle .

thanks

Brains 07-25-2010 08:34 PM

Quote:

I don't think we know for sure that SurbhiJain is running this from a bash shell
This is one of the many reasons it helps to know which Linux distribution the OP is using (Put it in the profile), which would make it easier for those that want to help, make better assumptions.

SurbhiJain 07-25-2010 08:51 PM

hmmm. will do...but cud u pls tell me why are those errors coming?

tommylovell 07-25-2010 08:57 PM

Aha. I think the the giveaway here is the "rm: cannot remove '/tmp/*.log\r': no such file or directory".

I don't think you have legitimate lineend characters in your script file, as evidenced by the '\r' in that error message. This sometimes happens when the file comes from another (usually inferior) operating system.

Type "hexdump -C setup_perflab.sh". It will show you the return character on each line of text. Each line should be immediately followed by a '0a'. The '\r' is (I think) a hex '0d' only. If you vi that file, it may show a '^m' on the end of each line. Also, 'file setup_perflab.sh' may tell you that it's format is other than "ASCII text".

(I've seen where ascii files from alien systems have left a ^m on the end of each line. 'bash' doesn't like when a line is terminated improperly -- it tags that character onto your command, whence the 'cd' failing, which makes the rest of the script fail...)

If this is the case, I'm not certain that 'dos2unix' will fix that file for you, but you can make a copy of the script and experiment on that copy. Otherwise you will have to edit the file to remove them, or use 'tr' to do the same.

Respond of this is the case or not. Thanks.

Brains, I agree with you. It's hard to remotely debug a problem when you are making assumptions regarding the distro, version, etc. But it is bash, and 3.2, so not too old. I'm hoping for bad termination characters.

SurbhiJain 07-25-2010 10:06 PM

dos2unix command has surely helped me...Now it has come down to only one error that is :

'./setup_perflab.sh':line 13 :./env : No Such file or directory.

i think, it executes the script after showing the above error message but not sure will error message affect anyway?

Any pointers for solving the above error?

tommylovell 07-25-2010 11:17 PM

That one is tough. That file is being sourced. Sourced files often contain functions and often set environmental variables (I think it's safe to say that a file named "env" is going to set environmental variables).

I don't know much about Oracle. But since the Oracle systems I have access to have neither "setup_perflab.sh" nor a file named "env" (so these don't appear to be provided samples), my guess is that they were created locally. And given the name "setup_perflab.sh", it sounds local.

I think you need to find whoever created that shell script and ask them what "env" needs to contain. Certainly you need to set at least $PERFLAB_USER, but there may be more variables that are required by other scripts.

Sorry I can't help with that.

Brains 07-26-2010 12:35 AM

I know nothing about Oracle. But at line 13 of the script, something looks funny to me and I highlight it in red below:
Code:

#
# source environment
#
. ./env

#
# Run the install script to setup the database

Should it not be as in the example below?
Code:

#
# source environment
#
./env

#
# Run the install script to setup the database


tommylovell 07-26-2010 10:07 AM

No, I don't think so. I beleive ". ./env" is correct. It just looks peculiar.

The first '.' is to "source the ./env file".

See http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x237.html

Or better yet, http://tldp.org/LDP/abs/html/internal.html

Quote:

source, . (dot command)

This command, when invoked from the command-line, executes a script. Within a script, a source file-name loads the file file-name. Sourcing a file (dot-command) imports code into the script, appending to the script (same effect as the #include directive in a C program). The net result is the same as if the "sourced" lines of code were physically present in the body of the script. This is useful in situations when multiple scripts use a common data file or function lib
It could have been ". $HOME/wkdir/env" for better readibility. It's a matter of preference.

SurbhiJain 07-26-2010 10:16 AM

hi tommylevell,

You are correct.Script is showing the right way of executing . ./env. Now the script is working fine. I just used dos2unix command on env as well and it is executing without any errors.

Thank you so much for your help. Your expertise has made my first experience with this forum and linux a pleasant one.

Surbhi


All times are GMT -5. The time now is 08:12 AM.