0

i know that this question has bin asked & answered a lot of times and i think i have read all of them :-( but still don't got it working :-(

OK, using CentOS release 8.2.2004 (Core) in root's cron i call a script

*/1 * * * * /bin/bash /home/getSSHsessions.sh 

the script just creates a file with some process listing

[root@myhost]# cat /home/getSSHsessions.sh #!/bin/bash /usr/bin/netstat -tnpa | /usr/bin/grep "VERBUNDEN.*sshd" > /mnt/ramdisk/sshsession.ls 

but the output is just a empty file

[root@myhost]# ll /mnt/ramdisk/ -rw-r--r--. 1 root root 0 5. Okt 19:33 sshsession.ls 

I get crazy about that. Really don't know any more where to look.

Ah, yes, the script works fine run as user root on cmd-line. Then it creates the output as it should.

[root@myhost]# cat /home/getSSHsessions.sh #!/bin/bash /usr/bin/netstat -tnpa | /usr/bin/grep "VERBUNDEN.*sshd" > /mnt/ramdisk/sshsession.ls [root@saprouter iteanova]# /home/getSSHsessions.sh [root@myhost]# ll /mnt/ramdisk/ -rw-r--r--. 1 root root 404 6. Okt 10:46 sshsession.ls [root@myhost]# cat /mnt/ramdisk/sshsession.ls tcp 0 0 192.168.137.4:54782 192.168.137.2:80 VERBUNDEN 309654/sshd: myuser tcp 0 0 192.168.137.4:22 95.208.219.123:33300 VERBUNDEN 309622/sshd: myuser tcp 0 0 192.168.137.4:22 95.208.219.123:60744 VERBUNDEN 308085/sshd: myuser tcp 0 0 192.168.137.4:22 35.203.68.135:36564 VERBUNDEN 310513/sshd: root [ 
4
  • 3
    Is it possible that root uses English and you have to grep for connected instead of verbunden? Commented Oct 5, 2020 at 18:00
  • 1
    still, in your getSSHsessions run the command without grep so you can see the output. this will make it easier to find the cause Commented Oct 5, 2020 at 18:23
  • Check your Linux mail account. Anything that leaks out of a cron job (like stderr) is mailed to your local user. Alternatively, add a redirect 2>myCron.log to the cron entry and check the file. Commented Oct 5, 2020 at 22:41
  • As is said in the post, when starting the script as root on cmdline, i got the output as i expect. I have updated the post qwith the relevant info. Commented Oct 6, 2020 at 8:45

1 Answer 1

0

OK, i got the reason of the problem.

Someone pointed me to the language settings, which was right.

It seems that in CentOS the environment between a login-shell and a non-login shell are heavily different.

While root uses german as language in root-login-shell, it is set to english in root non-login shell (shell called from cron).

:-(

and same is the output of netstat.

OK, thanks for the hint.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.