Task script not running

badincite

Dabbler
Joined
Aug 10, 2022
Messages
20
Trying to run this script below basically just a modified version of Spearfoot's rescan datastores. Doesn't appear to be working nothing written into the log and I know it works when I run it from the TrueNAS shell.


rescan.sh
Code:
#!/bin/bash

echo "$(date): Forcing datastore rescan on ESXi host 192.168.1.20" | tee -a "esxi-rescan-datastores.log"

ssh -i esxi root@192.168.1.20

esxcli storage core adapter rescan --all && exit

echo "Done"



1660500558532.png
 

badincite

Dabbler
Joined
Aug 10, 2022
Messages
20
So I set it up as a cron job and got a permissions issue corrected that. Now getting
Pseudo-terminal will not be allocated because stdin is not a terminal.
/mnt/test1/rescan1.sh: line 3: esxcli: command not found


Modified my script to this and tested in TrueNAS shell runs fine there just not in cron or task scripts.

Code:
ssh -T -i esxi root@192.168.1.20
esxcli storage core adapter rescan --all
exit
 
Last edited:

badincite

Dabbler
Joined
Aug 10, 2022
Messages
20
Modified to this now it works.:rolleyes:

Code:
#!/bin/sh
echo "$(date): Forcing datastore rescan on ESXi host" | tee -a "/mnt/test1/rescan.log"
ssh -i /root/esxi root@192.168.1.20 esxcli storage core adapter rescan --all


So mistakes made
  1. Needed to add execute permissions on file
  2. Change code to single line
  3. Cron Executes in the user directory while task executes in the main directory. So full paths need to be defined when running task.
 
Last edited:
Top