Solved "No such file or directory"

I have this simple (looks simple to me!) procedure file (~/get_smart_daily)
Code:
#!/bin/sh
rm ~/smart_data
/usr/local/sbin/smartctl -t short -d ata /dev/ada0
/usr/local/sbin/smartctl -t short -d ata /dev/ada1
/usr/local/sbin/smartctl -t short -d ata /dev/ada2
/usr/local/sbin/smartctl -t short -d ata /dev/ada3
sleep 1800
/usr/local/sbin/smartctl -HAl selftest -d ata /dev/ada0 > ~/smart_data
/usr/local/sbin/smartctl -HAl selftest -d ata /dev/ada1 >> ~/smart_data
/usr/local/sbin/smartctl -HAl selftest -d ata /dev/ada2 >> ~/smart_data
/usr/local/sbin/smartctl -HAl selftest -d ata /dev/ada3 >> ~/smart_data
mail -s "daily smart status" root < ~/smart_data

But when I try running it by hand ( sh -x ~/get_smart_daily) for debugging, it complains
Code:
sh -x ~/get_smart_daily
+ rm /root/smart_data
: No such file or directory
+ /usr/local/sbin/smartctl -t short -d ata /dev/ada0
smartctl 6.4 2015-06-04 r4109 [FreeBSD 10.2-RELEASE amd64] (local build)
Copyright (C) 2002-15, Bruce Allen, Christian Franke, www.smartmontools.org

 failed: No such file or directory
+ /usr/local/sbin/smartctl -t short -d ata /dev/ada1
smartctl 6.4 2015-06-04 r4109 [FreeBSD 10.2-RELEASE amd64] (local build)
Copyright (C) 2002-15, Bruce Allen, Christian Franke, www.smartmontools.org

 failed: No such file or directory
+ /usr/local/sbin/smartctl -t short -d ata /dev/ada2
smartctl 6.4 2015-06-04 r4109 [FreeBSD 10.2-RELEASE amd64] (local build)
Copyright (C) 2002-15, Bruce Allen, Christian Franke, www.smartmontools.org

 failed: No such file or directory
+ /usr/local/sbin/smartctl -t short -d ata /dev/ada3
smartctl 6.4 2015-06-04 r4109 [FreeBSD 10.2-RELEASE amd64] (local build)
Copyright (C) 2002-15, Bruce Allen, Christian Franke, www.smartmontools.org

 failed: No such file or directory
+ sleep 1800

...and I've no idea what it thinks it's complaining about. The only file mentioned, apart from ~/smart_data which hasn't been created yet, is smartctl and it's obviously finding that.
 
I have tried
Code:
 # /usr/local/sbin/smartctl -t short -d ata /dev/ada0
smartctl 6.5 2016-05-07 r4318 [FreeBSD 10.3-STABLE amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

Read Device Identity failed: Inappropriate ioctl for device
Just /usr/local/sbin/smartctl -t short /dev/ada0 works here. I have tried that because I have never used the option -d.
 
I first tried it without the -d because that worked fine from the command line, but it wouldn't work in the procedure file for some reason. It made no sense to me, but I put it in to silence the complaint. Unfortunately that still left the "no such file" complaint, which I can't figure out at all.
 
Make sure you haven't created the script file with CR+LF linefeeds or non-breaking spaces (ASCII character 160), they will produce errors exactly like that.
 
Make sure you haven't created the script file with CR+LF linefeeds or non-breaking spaces (ASCII character 160), they will produce errors exactly like that.

Psia krew i psia kość! That's exactly what it was: I created the file with slickedit under xp, and then, for my inconvenience, geany continued to preserve the CRLF eols.

To get completely confused by CR chars? That's ridiculously excessive fragility! It would have taken me a year to discover that that was the problem.
 
For anyone who wants a simple file that works, feel free to edit this to suit yourself (but not under windows unless your editor uses LF eols)

Code:
#!/bin/tcsh
rm ~/smart_data
touch ~/smart_data
set disc = 0
while( $disc < 4 )
    /usr/local/sbin/smartctl -t short /dev/ada$disc
    @ disc++
end
sleep 240
set disc = 0
while( $disc < 4 )
    printf "\n\n================ BEGIN DISC $disc ================\n\n" >> ~/smart_data
    /usr/local/sbin/smartctl -HA /dev/ada$disc >> ~/smart_data
    /usr/local/sbin/smartctl -l selftest /dev/ada$disc >> ~/smart_data
    @ disc++
end
cat ~/smart_data | mail -s "Daily SMART data results" root
 
Back
Top