Solved [Solved] file not found in script but found in command-line

globus999

New Member


Messages: 6

I have an old implementation of FreeNAS running FreeBSD 9.0 RC2. I need to run a very simple script:

Code:
#!/bin/sh
echo "$1"
echo /tank1/validation/"$1"
mount -t cd9660 /dev/cd0 /mnt/cdfn0
cp -R -n /mnt/cdfn0/* /tank1/validation/"$1"
umount /mnt/cdfn0
chmod -R 777 /tank1/validation/"$1"
camcontrol eject cd0
Unfortunately, for some inscrutable reason, when the shell executes:
Code:
mount -t cd9660 /dev/cd0 /mnt/cdfn0
it throws an error as file not found? (it is not finding cdfn0) and it never mounts the CD rom. However, if I execute every single frigging line manually (one by one) it works OK! WTF?

Any idea what's wrong?

The value of $1 that I am using is not a switch but arbitrary text to create a folder name. Since this system is an old FreeNAS, it lacks the read command and so this is the only way I found to pass the name of a variable to the script. I have to migrate close to 400 CD's and DVD's into a FreeNAS system.

When I run the script with the -x parameter I get:

Code:
freenas:/tank1# sh -x cd0iso.sh A005
+ echo A005
A005
+ echo /tank1/validation/A005
/tank1/validation/A005
+ mount -t cd9660 /dev/cd0 /mnt/cdfn0
: No such file or directory
+ cp -R -n '/mnt/cdfn0/*' /tank1/validation/A005
cp: /mnt/cdfn0/*: No such file or directory
+ umount /mnt/cdfn0
: statfs: No such file or directory
: unknown file system
+ chmod -R 777 /tank1/validation/A005
: No such file or directory05
+ camcontrol eject cd0
camcontrol: cam_get_device: unable to find device unit number
+
: not found
+
: not found
+
: not found
As far as I can tell, the line that is failing is the mount line.

As to chmod 777, yes, I know, but the system is on a closed LAN with zero chances of being hacked. It simply makes my life easier.

Oh, FYI, I can strip the script down to the mount line only (no parameters to pass) and it still fails. If I take the mount line verbatim and execute it manually, it works without any problems. FYI #2: I am logged in as root, so there are no rights issues either.

Any ideas?
 

kpa

Beastie's Twin

Reaction score: 1,809
Messages: 6,318

Re: file not found in script but found in command line mode?

Check for a rogue shift-space in place of a space somewhere in your script. I tend to fat finger shift-space very often after the pipe (|) character and the command line doesn't work because of that.
 
OP
OP
G

globus999

New Member


Messages: 6

Re: file not found in script but found in command line mode?

Tx Thanks! I think you are on the right track. I stripped the script down to:

Code:
#!/bin/sh
mount -t cd9660 /dev/cd0 /mnt/cdfn0
Using Notepad++ and re-typed everything.
It works if it use it as-is, however, if I try to keep typing other commands, as soon as I punch in a return at the end of the mount code it throws the same error. It would seem that is taking an EOL as a character? Which editor should I use then?

TxThanks again!
 
OP
OP
G

globus999

New Member


Messages: 6

Re: file not found in script but found in command line mode?

Nevermind, it was the LF vs LFCR issue.
I guess I am too used to Linux.
Tx! Thanks!
 

wblock@

Beastie Himself
Developer

Reaction score: 3,646
Messages: 13,850

Re: file not found in script but found in command line mode?

read is supposed to be a sh(1) builtin.

Use hd(1) to view the actual output of commands. It will make extra CRs obvious.

As far as chmod 777, "making life easier" is always the reason it is used. It should always feel like a mistake.
 

_martin

Aspiring Daemon

Reaction score: 167
Messages: 802

Re: file not found in script but found in command line mode?

Also cat -et <file> is a good way to check for non-printing characters.
 
Top