So building on my last question here I got it to work, but then I tried making a crontab out of it, to check the number of lines at a given date every 2 minutes.
So my script looks like this
1 test=/root/test
2 n="$(cat /root/test)"
3 t="$(date)"
4 echo "there were $n lines in $test at $t" >> rtest1
And whenever I run the script, rtest1 shows me the desired result:
there were 224 lines in /root/test at Fri Aug 10 10:28:25 EEST 2018
there were 224 lines in /root/test at Fri Aug 10 10:28:25 EEST 2018
there were 224 lines in /root/test at Fri Aug 10 10:28:26 EEST 2018
there were 224 lines in /root/test at Fri Aug 10 10:28:26 EEST 2018
there were 224 lines in /root/test at Fri Aug 10 10:28:26 EEST 2018
there were 224 lines in /root/test at Fri Aug 10 10:28:26 EEST 2018
However, when it happens because of the crontab, for some bizzare reason, sometimes it omits the lines number like so:
there were 229 lines in /root/test at Fri Aug 10 10:20:51 EEST 2018
there were lines in /root/test at Fri Aug 10 10:22:01 EEST 2018
there were 224 lines in /root/test at Fri Aug 10 10:24:01 EEST 2018
there were 224 lines in /root/test at Fri Aug 10 10:26:02 EEST 2018
there were lines in /root/test at Fri Aug 10 10:28:01 EEST 2018
This is how my crontab looks like:
[root@centos7desk ~]# crontab -l
* * * * * ps axu | wc -l > /root/test
*/2 * * * * /root/script.sh
I have no idea why this happens.