Script

Jost Wittmann

Dabbler
Joined
Feb 23, 2014
Messages
34
Hi!
I am trying to get a simple script running on FreeNAS 11.3U2-1.

The first two lines/commands are supposed to create a directory:
Code:
#!/bin/bash
mkdir path/to/directory/$1/subdirectory2


I run the script from the FreeNAS shell:
Code:
sh path/to/script.sh subdirectory1


I have set the permissions of the script to 777 - temporarily.

I get the response that the directory path/to/directory/subdirectory1/subdiretory2 does not exist („No such file or directory“). Consequently, all following commands of the script fail, because they are supposed to change ownership an permissions of the new direcctories.

If I run the command as a user of the group wheel, („su username sh ....“) I get no errormessages. But still, the directories do not get created.
If I copy and paste the commands from the script into the shell, they work perfectly (run as root user).

What am I missing here? Thanks for helping!
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
You're using relative instead of absolute paths. Try the full path instead.
 

Jost Wittmann

Dabbler
Joined
Feb 23, 2014
Messages
34
Thank you for your reply, but I am actually using abolute paths, starting with /mnt/....
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Why oh why is there a /bin/bash symlink in FreeNAS? iXsysteeeeeeeeeems! :smile:
Bash scripting - don't. There's /bin/sh and there's POSIX.
 

Jost Wittmann

Dabbler
Joined
Feb 23, 2014
Messages
34
Thanks Patrick. Now: Once again please - in slow motion. My first freeNAS-script ever...
I exchanged the
Code:
#!/bin/bash
with
Code:
/bin/sh
. No improvement...

I (believe to) understand that sh and bash are different type of terminals. But commands like "mkdir", "chown", and "chmod" should be kind of universal, no?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
sh and bash are different shells. Your script should start with
#! /bin/sh

You can debug what is going on by executing sh -x /path/to/your/script.sh while logged in via ssh.

Show us the output of that command if you have more questions. My rant above was not specifically directed at you. :wink:
 

Jost Wittmann

Dabbler
Joined
Feb 23, 2014
Messages
34
Right: while preparing this post, I realized my mistake: I used the "mkdir" command to create not only a new directory, but also a new directory in that new directory. That is what caused the error. If I create one new directory at the time, it's running fine.

So all I have to do (besides changing the first line) is add a "-p" to the mkdir command.

Thanks for your help! problem solved :smile:
 
Top