LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 07-25-2010, 01:47 PM   #1
SurbhiJain
LQ Newbie
 
Registered: Jul 2010
Location: NJ
Distribution: i686-redhat linux gnu 3.2.25
Posts: 10

Rep: Reputation: 0
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.
 
Old 07-25-2010, 03:04 PM   #2
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 258

Rep: Reputation: 42
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.
 
Old 07-25-2010, 03:43 PM   #3
SurbhiJain
LQ Newbie
 
Registered: Jul 2010
Location: NJ
Distribution: i686-redhat linux gnu 3.2.25
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
Old 07-25-2010, 03:57 PM   #4
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 258

Rep: Reputation: 42
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.

Last edited by Brains; 07-25-2010 at 04:00 PM.
 
Old 07-25-2010, 04:32 PM   #5
SurbhiJain
LQ Newbie
 
Registered: Jul 2010
Location: NJ
Distribution: i686-redhat linux gnu 3.2.25
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
Old 07-25-2010, 06:09 PM   #6
tommylovell
Member
 
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372

Rep: Reputation: 101Reputation: 101
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.

Last edited by tommylovell; 07-25-2010 at 06:12 PM.
 
Old 07-25-2010, 06:25 PM   #7
SurbhiJain
LQ Newbie
 
Registered: Jul 2010
Location: NJ
Distribution: i686-redhat linux gnu 3.2.25
Posts: 10

Original Poster
Rep: Reputation: 0
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
Attached Images
File Type: jpg cmd.jpg (148.7 KB, 9 views)
 
Old 07-25-2010, 07:34 PM   #8
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 258

Rep: Reputation: 42
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.
 
Old 07-25-2010, 07:51 PM   #9
SurbhiJain
LQ Newbie
 
Registered: Jul 2010
Location: NJ
Distribution: i686-redhat linux gnu 3.2.25
Posts: 10

Original Poster
Rep: Reputation: 0
hmmm. will do...but cud u pls tell me why are those errors coming?
 
Old 07-25-2010, 07:57 PM   #10
tommylovell
Member
 
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372

Rep: Reputation: 101Reputation: 101
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.

Last edited by tommylovell; 07-25-2010 at 08:07 PM. Reason: correct text
 
Old 07-25-2010, 09:06 PM   #11
SurbhiJain
LQ Newbie
 
Registered: Jul 2010
Location: NJ
Distribution: i686-redhat linux gnu 3.2.25
Posts: 10

Original Poster
Rep: Reputation: 0
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?
 
Old 07-25-2010, 10:17 PM   #12
tommylovell
Member
 
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372

Rep: Reputation: 101Reputation: 101
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.
 
Old 07-25-2010, 11:35 PM   #13
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 258

Rep: Reputation: 42
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
 
Old 07-26-2010, 09:07 AM   #14
tommylovell
Member
 
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372

Rep: Reputation: 101Reputation: 101
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.
 
Old 07-26-2010, 09:16 AM   #15
SurbhiJain
LQ Newbie
 
Registered: Jul 2010
Location: NJ
Distribution: i686-redhat linux gnu 3.2.25
Posts: 10

Original Poster
Rep: Reputation: 0
Smile

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
 
  


Reply

Tags
command, found, script, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem executing mv command inside shell script pablogosse Linux - General 7 12-16-2009 12:21 PM
Sntax error : unexpected end of file while executing shell script priyankarathi Linux - Newbie 5 04-21-2009 01:33 AM
Executing a command in Shell Script gjagadish Programming 7 10-15-2007 04:23 AM
Can't seem to run a simple shell script error command not found each time SimonT Linux - Newbie 5 10-29-2006 06:31 AM
Executing a shell script command!! vishamr2000 Programming 4 08-15-2005 12:33 AM


All times are GMT -5. The time now is 10:31 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration