How to install scripts

Status
Not open for further replies.

Gert VD

Cadet
Joined
Jun 26, 2013
Messages
6
I have found some interesting scripts I would like to run on my freenas. Unfortunately, as a N00b, I have no clue how to install these scripts.
  1. If I find a script in a forum, I should copy/write it in a text editor (fe: Vim)?
  2. Save as : *.sh ?
  3. Save where?
  4. I should give permission to execute using chmod?
  5. How do I finally run it?
I have been googling around and have found a few guides for scripting, but nowhere found an answer to a basic question like :where to save my scripts. Any enlightment or pointing me in the right direction (good basic guides) would be welcome.

G.

freenas 8.3.1
 

tingo

Contributor
Joined
Nov 5, 2011
Messages
137
1 and 4: yes
2: not required, you could just name it "command" for instance (without the quotes) - take care not to give it the same name as an existing command or script.
3: Create a directory in the home directory of your user called "bin" (again, without the quotes, so $HOME/bin) for example. This is already in the $PATH, if you choose another directory, you will need to change $PATH.
5. By giving it's name in a shell (from ssh for example): "command" (again, without the quotes.
 

Gert VD

Cadet
Joined
Jun 26, 2013
Messages
6
Ok,

I executed these steps:
  1. created a directory "bin" using windows explorer in "Freenas win" (the windows share I made, which is located on /mnt/NASDisk2, which is also the homedirectory for my user-id.
  2. executed this command in the shell: chmod u+x /mnt/NASDisk2/bin/temp.sh (nothing visualy happend here)
  3. executed this in shell: /bin/sh /mnt/NASDisk2/bin/temp.sh
by just typing "temp.sh" in the shell, nothing happend. It just said: bash: temp.sh: command not found
Here is the script I copied and the result I got in the shell. I am very sure I'm making some mistake(s) here :smile:
ps: the script and above commands are googled, I have very little understanding of what they mean in detail.

script:
Code:
1.#! /bin/sh
 
2.echo "CPU temp :"
 
3.sysctl -a |egrep -E "cpu\.[0-9]+\.temp"
 
4.echo
 
5.echo "HDD temp :"
 
6.for i in $(sysctl -n kern.disks)
 
7.do
 
8.        DevTemp=`smartctl -a /dev/$i | awk '/Temperature_Celsius/{print $0}' | awk '{print $10 "C"}'`
 
9.        DevSerNum=`smartctl -a /dev/$i | awk '/Serial Number:/{print $0}' | awk '{print $3}'`
 
10.        DevName=`smartctl -a /dev/$i | awk '/Device Model:/{print $0}' | awk '{print $3}'`
 
11.        echo $i $DevTemp $DevSerNum $DevName
 
12.done
 
13.
 


and shell:

[root@freenas ~]# /bin/sh /mnt/NASDisk2/temp.sh

/mnt/NASDisk2/temp.sh: Can't open /mnt/NASDisk2/temp.sh: No such file or directory

[root@freenas ~]# /bin/sh /mnt/NASDisk2/bin/temp.sh

1.#!: not found

2.echo: not found

3.sysctl: not found

: not found

5.echo: not found

6.for: not found

: not found

8.: not found

9.: not found

10.: not found

11.: not found

: not found

: not found

: not found

: not found

[root@freenas ~]#

 

ChiknNutz

Patron
Joined
Nov 6, 2015
Messages
217
I am trying to accomplish the same thing and get an "illegal option" when doing so. What am I doing wrong here?
 

Dariusz1989

Contributor
Joined
Aug 22, 2017
Messages
185
Digging out old topic. Trying to learn how to run scripts on freenas... I got this

mnt/myVolume/myDataset/foldername/scriptName.sh When I run that I just get /bin/sh^M: bad interpreter: No Such file or directory. Can any1 help?
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194
Status
Not open for further replies.
Top