Thread: Newbie Bash scripting issues
hi all,
extremely unexperienced in writing in bash , not experienced coding @ all, have no issue learning.
trying implement mail alert when of gpu temperature sensors go below centigrade. plan on using cron job runs every 10-15 minutes or , sends mail through exim , smarthost if pre-mentioned conditions met.
below bash script have far:
everything below line 6 testing variables grabbed correctly , whether condition working.code:#!/bin/bash min="80" temp0= display=:0 aticonfig --odgt --adapter=0 | sed -n '/[0-9][0-9]\.[0-9][0-9]/,$p' | sed 's/.*\([0-9][0-9]\)\..*/\1/' temp1= display=:0 aticonfig --odgt --adapter=1 | sed -n '/[0-9][0-9]\.[0-9][0-9]/,$p' | sed 's/.*\([0-9][0-9]\)\..*/\1/' temp2= display=:0 aticonfig --odgt --adapter=2 | sed -n '/[0-9][0-9]\.[0-9][0-9]/,$p' | sed 's/.*\([0-9][0-9]\)\..*/\1/' temp3= display=:0 aticonfig --odgt --adapter=3 | sed -n '/[0-9][0-9]\.[0-9][0-9]/,$p' | sed 's/.*\([0-9][0-9]\)\..*/\1/' echo $temp0 echo $temp1 echo $temp2 echo $temp3 echo $min if [ "$temp0" -lt "$min" ]; echo "something not right..." else echo "everything looks ok" fi
condition plan on using 4 temperature's being checked against $min using || operator.
when run script following:
now, expect if statement executed, rather else statement. assuming else statement being triggered because there sort of error in comparison can't work out.code:76 74 70 74 80 tempcheck.sh: line 12: [: : integer expression expected looks ok
reference, here output display=:0 aticonfig cmd before sed gets it:
any appreciated.code::~# display=:0 aticonfig --odgt --adapter=0 adapter 0 - ati radeon hd 5800 series sensor 0: temperature - 76.00 c
jg
edit: realise how messy sed / regex , appreciate if me clean up, again.
you don't capture output if sees null value
notice 4 empty lines in output, that's echo $temp0 ... echo $temp3 sequence. can see variables empty
if sure there 1 occurence of [0-9]{2}.[0-9]{2} can use grep -o returns matching part (76.00), simplify next part fraction part dropped.code:temp0=$( display=:0 aticonfig --odgt --adapter=0 .... )
note used {2,3} allow numbers above 100code:echo $'test 6.66\ntest 76.00\ntest 112.99' test 6.66 test 76.00 test 112.99 echo $'test 6.66\ntest 76.00\ntest 112.99' | grep -oe '[0-9]{2,3}[.][0-9]{2}' | sed -r 's/([0-9]*).*/\1/g' 76 112
sed -r allows dropping painful escaping thing of dots, parentheses , stuff assumes have regex meaning.
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] Newbie Bash scripting issues
Ubuntu
Comments
Post a Comment