I have this shell, thingy.sh:
$ cat tb/thingy.sh
#!/bin/sh
STORE_FILE=$PWD/ycycleoutput
SLEEP_INTERVAL=5 #seconds
let "COUNT = 60 * 60 * 24 / $SLEEP_INTERVAL"
CUR_MAX_PROC=-1
count_cur_num()
{
CUR_NUM_PROC=`ps aux | grep -E '^myuser' | wc -l`
}
store_cur_max_in_file()
{
if [ -f "$STORE_FILE" ]; then
. "$STORE_FILE"
fi
if [ $CUR_NUM_PROC -gt $CUR_MAX_PROC ]; then
echo CUR_MAX_PROC=$CUR_NUM_PROC > $STORE_FILE
fi
}
while [ $COUNT -gt 0 ]; do
count_cur_num
store_cur_max_in_file
let "COUNT = $COUNT - 1"
let "MOD = $COUNT % 100"
if [ $MOD -eq 0 ]; then
echo "COUNT is $COUNT and CUR_MAX_PROC is $CUR_MAX_PROC"
fi
sleep $SLEEP_INTERVAL
done
--snip--
On CentOS 7 and OpenSuSE it runs fine. On Ubuntu 16.04 I get:
$ tb/thingy.sh
tb/thingy.sh: 6: tb/thingy.sh: let: not found
tb/thingy.sh: 26: [: -gt: unexpected operator