Ubuntu Pastebin

Paste from ycyclist on irc at Fri, 6 Oct 2017 22:00:26 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
Download as text