FreeNAS Shell vs Other SSH Programs

Status
Not open for further replies.

Thousandbuckle

Contributor
Joined
Jul 9, 2014
Messages
136
Hello all, I have found that I can run a command through the FreeNAS shell in the webgui but doing the same command through Putty ssh connection to FreeNAS box I get error. What would be the reason for getting the different results from the Shell vs Other SSH programs? What is the best way to connect to FreeNAS box outside of using the built in shell?

The command I am issuing is the text below.
  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
In the FreeNAS shell I get this result which seems to work properly:

[root@FreeNAS ~]# #! /bin/sh
[root@FreeNAS ~]# echo "CPU temp :"
CPU temp :
[root@FreeNAS ~]# sysctl -a |egrep -E "cpu\.[0-9]+\.temp"
dev.cpu.3.temperature: 42.0C
dev.cpu.2.temperature: 44.0C
dev.cpu.1.temperature: 43.0C
dev.cpu.0.temperature: 45.0C
[root@FreeNAS ~]# echo

[root@FreeNAS ~]# echo "HDD temp :"
HDD temp :
[root@FreeNAS ~]# for i in $(sysctl -n kern.disks)
> do
> DevTemp=`smartctl -a /dev/$i | awk '/Temperature_Celsius/{print $0}' | awk '{print $10 "C"}'`
> DevSerNum=`smartctl -a /dev/$i | awk '/Serial Number:/{print $0}' | awk '{print $3}'`
> DevName=`smartctl -a /dev/$i | awk '/Device Model:/{print $0}' | awk '{print $3}'`
> echo $i $DevTemp $DevSerNum $DevName
> done
da0
ada3 36C WD-WCC4M0083526 WDC
ada2 36C WD-WCC4M0087224 WDC
ada1 32C WD-WCC4M0097463 WDC
ada0 33C WD-WCC4M0099604 WDC

If I use Putty SSH connection I get a partial success for CPU but for HD I get some kind of issue/error the red text below. If I hit enter it keeps scrolling pages of the numeric values in red listed below:

[root@FreeNAS] ~# #! /bin/sh
#!: Command not found.
[root@FreeNAS] ~# echo "CPU temp :"
CPU temp :
[root@FreeNAS] ~# sysctl -a |egrep -E "cpu\.[0-9]+\.temp"
dev.cpu.3.temperature: 43.0C
dev.cpu.2.temperature: 44.0C
dev.cpu.1.temperature: 48.0C
dev.cpu.0.temperature: 43.0C
[root@FreeNAS] ~# echo

[root@FreeNAS] ~# echo "HDD temp :"
HDD temp :
[root@FreeNAS] ~# for i in $(sysctl -n kern.disks)
Illegal variable name.
[root@FreeNAS] ~# do

CORRECT>od (y|n|e|a)? yes
0000000 020040 020040 020040 042040 073145 062524 070155 060075
0000020 066563 071141 061564 066164 026440 020141 062057 073145
0000040 022057 020151 020174 073541 020153 027447 062524 070155
 

depasseg

FreeNAS Replicant
Joined
Sep 16, 2014
Messages
2,874
Looks like putty isn't letting you change shells (lines 1&2). What shell are you running (likely bash), and maybe whatever shell that is has a different syntax. I think echo $0 will tell you your configured shell.
 

Sakuru

Guru
Joined
Nov 20, 2015
Messages
527
I see one issue right off the bat
Code:
#! /bin/sh

Has a space after the #! that shouldn't be there. It should look like this:
Code:
#!/bin/sh

Also, how are you running this script? It looks like you are pasting it into the terminal instead of running like a script.
 

SweetAndLow

Sweet'NASty
Joined
Nov 6, 2013
Messages
6,421
You are using a different shell. Put all of this in a script with a proper shebang that matches your script syntax.
 
Status
Not open for further replies.
Top