my Script to Beep MB buzzer if pool degraded

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Please screenshot the cron task settings and post them here.
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
Please screenshot the cron task settings and post them here.
屏幕截图 2023-03-14 205204.png
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
OK, so there's your problem... you're not running the script, you're marking it as executable (chmod +x)

First, in a shell, run /usr/local/bin/dkbox1.sh

See if there's any output (and if it beeps).

If it's OK, change the cron task command to /usr/local/bin/dkbox1.sh
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
OK, so there's your problem... you're not running the script, you're marking it as executable (chmod +x)

First, in a shell, run /usr/local/bin/dkbox1.sh

See if there's any output (and if it beeps).

If it's OK, change the cron task command to /usr/local/bin/dkbox1.sh
May I ask how should I run in the shell /usr/local/bin/dkbox1.sh ?
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
May I ask how should I run in the shell /usr/local/bin/dkbox1.sh ?
Go to the Shell tab in the GUI.

Type /usr/local/bin/dkbox1.sh press <ENTER>
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
Go to the Shell tab in the GUI.

Type /usr/local/bin/dkbox1.sh press <ENTER>
/usr/local/bin/dkbox1.sh: 1: Syntax error: "then" unexpected
Executed CronTask - /usr/local/bin/dkbox1.sh > /dev/null: /usr/local/bin/dkbox1.sh: 1: Syntax error: "then" unexpected
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
/usr/local/bin/dkbox1.sh: 1: Syntax error: "then" unexpected
Then there's something wrong with the script.

Are you sure that you changed only the line I mentioned to you and nothing else from the original script? It works when I run it.

Are you running CORE or SCALE?
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
Then there's something wrong with the script.

Are you sure that you changed only the line I mentioned to you and nothing else from the original script? It works when I run it.

Are you running CORE or SCALE?
TrueNAS Core 13.0-U4
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Can you share the output when you go to the Shell tab and type cat /usr/local/bin/dkbox1.sh press <ENTER>
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
Can you share the output when you go to the Shell tab and type cat /usr/local/bin/dkbox1.sh press <ENTER>
RESULT IN SYSTEM FAILURE.

root@truenas[~]# cat /usr/local/bin/dkbox1.sh
f zpool status -v | grep -q DEGRADED; then
echo Degraded Found
logger buzzerAlarm a pool is DEGRADED SOUND MB BUZZER
# run alarm 1800 times every .1 sec = sounds beeper for 180s / 3min exactly
for i in {1..1800}
do
sleep 0.1
/usr/bin/printf "\007" > /dev/ttyv0
done
# send to local and remote log
logger buzzerAlarm script JUST FINISHED fireing for 3min bc pool DEGRADED
else
echo phrase not found
# only occasionally (1 in 12 chance) send a log msg showing this script is running/working
if (( RANDOM % 12 )); then
logger buzzerAlarm script is running every 5min log msgs are random time
fi
fi
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
OK, well that's obviously not the same as needs to be in the file...

You're missing the first line and the first character of the second line.

Code:
#!/usr/local/bin/bash
if zpool status -v | grep -q DEGRADED; then
echo Degraded Found
logger buzzerAlarm a pool is DEGRADED SOUND MB BUZZER
# run alarm 1800 times every .1 sec = sounds beeper for 180s / 3min exactly
    for i in {1..1800}
    do
    sleep 0.1
    /usr/bin/printf "\007" > /dev/ttyv6
    done
# send to local and remote log
logger buzzerAlarm script JUST FINISHED fireing for 3min bc pool DEGRADED
else
echo phrase not found
# only occasionally (1 in 12 chance) send a log msg showing this script is running/working
if (( RANDOM % 12 )); then
logger buzzerAlarm script is running every 5min log msgs are random time
fi
fi
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
OK, well that's obviously not the same as needs to be in the file...

You're missing the first line and the first character of the second line.

Code:
#!/usr/local/bin/bash
if zpool status -v | grep -q DEGRADED; then
echo Degraded Found
logger buzzerAlarm a pool is DEGRADED SOUND MB BUZZER
# run alarm 1800 times every .1 sec = sounds beeper for 180s / 3min exactly
    for i in {1..1800}
    do
    sleep 0.1
    /usr/bin/printf "\007" > /dev/ttyv6
    done
# send to local and remote log
logger buzzerAlarm script JUST FINISHED fireing for 3min bc pool DEGRADED
else
echo phrase not found
# only occasionally (1 in 12 chance) send a log msg showing this script is running/working
if (( RANDOM % 12 )); then
logger buzzerAlarm script is running every 5min log msgs are random time
fi
fi
[root@truenas ~]# cat /usr/local/bin/dkbox23.sh

#!/usr/local/bin/bash
if zpool status -v | grep -q DEGRADED; then
echo Degraded Found
logger buzzerAlarm a pool is DEGRADED SOUND MB BUZZER
# run alarm 1800 times every .1 sec = sounds beeper for 180s / 3min exactly
for i in {1..1800}
do
sleep 0.1
/usr/bin/printf "\007" > /dev/ttyv0
done
# send to local and remote log
logger buzzerAlarm script JUST FINISHED fireing for 3min bc pool DEGRADED
else
echo phrase not found
# only occasionally (1 in 12 chance) send a log msg showing this script is running/working
if (( RANDOM % 12 )); then
logger buzzerAlarm script is running every 5min log msgs are random time
fi
fi


Is this correct?

root@truenas[~]# /usr/local/bin/dkbox23.sh
zsh: permission denied: /usr/local/bin/dkbox23.sh
root@truenas[~]# bash
[root@truenas ~]# /usr/local/bin/dkbox23.sh
bash: /usr/local/bin/dkbox23.sh: Permission denied
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
bash: /usr/local/bin/dkbox23.sh: Permission denied
so you created a new file...

You need to allow the new file to run:

chmod +x /usr/local/bin/dkbox23.sh

Then you can run it.
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
so you created a new file...

You need to allow the new file to run:

chmod +x /usr/local/bin/dkbox23.sh

Then you can run it.
The script does work, but there is no buzzer since my pool was downgraded. don't know what's wrong
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
So, let me summarize:

Your pool status shows degraded zpool status

You updated the script correctly and it generates no errors... but what does it output? it must say either Degraded found or phrase not found

If it outputs "Degraded found", I expect you should hear the beeping
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
So, let me summarize:

Your pool status shows degraded zpool status

You updated the script correctly and it generates no errors... but what does it output? it must say either Degraded found or phrase not found

If it outputs "Degraded found", I expect you should hear the beeping
屏幕截图 2023-03-15 200725.png

屏幕截图 2023-03-15 200700.png

Now the script can already run, I don't know why every time I create a script file, the pasted content always lacks the first letter of the first line and the second line. But now the script will only beep once every 1 minute after running, and will not make continuous sound.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
When you run it at the shell, does it beep continuously or just once? (I'm not sure if you're saying it works differently when it's a cron task)
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
When you run it at the shell, does it beep continuously or just once? (I'm not sure if you're saying it works differently when it's a cron task)
Run the script content directly in SHELL, it can make continuous sound for 3 minutes
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Try changing the cron task to run /bin/bash /usr/local/bin/dkbox23.sh
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
If that script is going to run every minute and last 3 minutes, you are going to have problems though.
 
Top