LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 01-14-2011, 05:41 AM   #1
eko000
LQ Newbie
 
Registered: Jan 2011
Posts: 2

Rep: Reputation: 0
Errors executing shell script: "command not found" and "no such file or directory"


Dear linux users,

I am new to shell scripting and any advice you have would be much appreciated.

A colleague gave me a shell script ("dti_motion") which needs to be run from the directory containing all the files it works on. I want to run the same script for several different directories. But I don't want to have to cd into each directory, run the script, wait for it to finish, and then cd to the next directory (there are 52 to do altogether).

So I wanted to write a very simple script that will cd to each directory and perform the script there, before going on to the next one.

My colleague's script ("dti_motion") is stored in my home/bin/ and is executable. My home/bin/ is in my path, as verified by echo $path. When run from a directory containing the necessary information, the dti_motion script works perfectly well.

I wrote an extremely inelegant script called "dti_motion_do_all" which is also stored in my home/bin/ and executable:

#!/bin/sh

#Get motion information for each subject, using Mark's script, called dti_motion

cd /imaging/cr01/PD_DTI/C_10/12x5
.dti_motion C10_12x5ec.ecclog (<--This .ecclog file is required by the dti_motion script as $1 and is stored in C_10/12x5)

cd /imaging/cr01/PD_DTI/C_10/30x2
.dti_motion C10_30x2ec.ecclog

#End of dti_motion_do_all script

When I type dti_motion_do_all at the command line to run it, this produces the error
/home/cr01/bin/dti_motion_do_all.sh: line 6: .dti_motion: command not found
/home/cr01/bin/dti_motion_do_all.sh: line 9: .dti_motion: command not found

I tried changing the dti_motion_do_all script to

#!/bin/sh

#Get motion information for each subject, using Mark's script, called dti_motion

cd /imaging/cr01/PD_DTI/C_10/12x5
. ./home/cr01/bin/dti_motion C10_12x5ec.ecclog

cd /imaging/cr01/PD_DTI/C_10/30x2
. ./home/cr01/bin/dti_motion C10_30x2ec.ecclog

#End of dti_motion_do_all script

And this then produces the following error when I run it:
/home/cr01/bin/dti_motion_do_all.sh: line 6: ./home/cr01/bin/dti_motion: No such file or directory
/home/cr01/bin/dti_motion_do_all.sh: line 9: ./home/cr01/bin/dti_motion: No such file or directory

I know there will be more elegant ways to write this script with loops, rather than simply using cd, but for the moment, I just want this to run, until I have learnt to use loops properly.

Does anyone have any suggestions for how to correct either of those "command not found" or "no such file or directory" errors, given that both the original dti_motion and my dti_motion_do_all script are in my /home/bin/ (which is on my path) and both scripts are executable?

Many thanks
 
Old 01-14-2011, 07:54 AM   #2
eko000
LQ Newbie
 
Registered: Jan 2011
Posts: 2

Original Poster
Rep: Reputation: 0
SOLVED - A colleague advised me, the dti_motion_do_all script should read:

#!/bin/sh

#Get motion information for each subject in each of the two datasets, using Mark's script, called dti_motion

cd /imaging/cr01/PD_DTI/C_10/12x5
/home/cr01/bin/dti_motion C10_12x5ec.ecclog

cd /imaging/cr01/PD_DTI/C_10/30x2
/home/cr01/bin/dti_motion C10_30x2ec.ecclog

#End of script

I just needed to explicitly tell the shell where to find the dti_motion script. This now works

Also, in case any other linux newbies find it useful, a looped version would look like this:

#!/bin/sh

#Get motion information for each subject in each of the two datasets, using Mark's script, called dti_motion

for i in {11,12} <--numbers of your directories
do

for j in {12x5,30x2} <--numbers of your directories
do

cd /imaging/cr01/PD_DTI/C_${i}/${j}
/home/cr01/bin/dti_motion C${i}_${j}ec.ecclog


done

done

#End of script
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
script executing-problem ("module: command not found") jovana.knezevic.83 Programming 8 02-18-2015 09:45 AM
automount 5.0.3 with auto.smb script yields "key "<name>" not found in map" rbergen Linux - Software 0 01-01-2010 12:27 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
executing a loaded module returns "command not found" error neelay1 Linux - Software 1 05-08-2006 02:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:52 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration