Incron doesn't do anything - centos7

I intstalled on a new vm with centos 7 incron.
I try to make it work but a simple command does nothing.
incrontab -e :
/home/test IN_CLOSE_WRITE touch "$#/$#.new"
nothing special
When i watch the log cron i see this :
May 13 11:40:57 Minions incrond[2785]: (root) CMD (touch "/home/test/test.new")
but nothing is created in the directory
[root#Minions test]# ll
total 0
-rw-r--r--. 1 root root 0 13 mai 11:40 test
Do you have an idea what is wrong ?

I just del quote like this :
/home/test IN_CLOSE_WRITE touch $#/$#.new

This is rather old but... maybe your incrond service isn't running.
# systemctl enable incrond.service
# systemctl start incrond.service

Related

Can't download a file via os.system('scp (...)') whithin a python script launched via a init script

I'm trying to download a remote file using the scp command called by os.system() in a Python script (scp.py) started as a service by a procd init script.
This script is running on OpenWrt 15.05.1 (which uses BusyBox to implement the shell environment). SCP itself is handled by dropbear SSH (https://matt.ucc.asn.au/dropbear/dropbear.html)
The code is quite simple :
import os
import logging
logging.basicConfig(level=logging.DEBUG, filename='/usr/local/www/log/scp_test.log', filemode = 'w')
rc = os.system('scp -i /root/.ssh/id_rsa root#vps500141.ovh.net:/root/simon/test /tmp/hello')
error_code, signal = rc >> 8, rc & 0xFF
logging.debug('error_code -> {}'.format(error_code))
logging.debug('signal -> {}'.format(signal))
When launched in the terminal using the command "python scp.py", the program's behave well. The download is successful and produces the following output :
root#S096C08:/usr/local/bin# python scp.py
test 100% 24 0.0KB/s 00:00
root#S096C08:/usr/local/bin# cat /usr/local/www/log/scp_test.log
DEBUG:root:error_code -> 0
DEBUG:root:signal -> 0
But this program fails to download anything when launched as a service using the command /etc/init.d/scp_test start
root#S096C08:/usr/local/bin# /etc/init.d/scp_test start
root#S096C08:/usr/local/bin# cat /usr/local/www/log/scp_test.log
DEBUG:root:error_code -> 1
DEBUG:root:signal -> 0
Furthermore, a quick investigation of the syslogs using the logread command shows this :
Wed May 15 10:24:58 2019 daemon.err python[3156]: Host 'vps500141.ovh.net' is not in the trusted hosts file.
Wed May 15 10:24:58 2019 daemon.err python[3156]: (ssh-rsa fingerprint md5 41:aa:2b:57:48:be:01:81:48:a3:d0:ac:b6:56:16:34)
Wed May 15 10:24:58 2019 daemon.err python[3156]: Do you want to continue connecting? (y/n)
Wed May 15 10:24:58 2019 daemon.err python[3156]: /usr/bin/dbclient: Connection to root#vps500141.ovh.net:22 exited: Didn't validate host key
vps500141.ovh.net already have an entry in /root/.ssh/known_hosts so this is quite surprising that it is not found when the script is running.
I've also tried to add the "-o StrictHostKeyChecking=no" option to the scp command but it doesn't seems to work either.
NB : this is the content of the init script /etc/init.d/scp_test
#!/bin/sh /etc/rc.common
# Copyright (C) 2015 CZ.NIC z.s.p.o. (http://www.nic.cz/)
START=99
STOP=0
USE_PROCD=1
SCRIPT="/usr/local/bin/scp.py"
start_service() {
procd_open_instance
procd_set_param user root
procd_set_param command python "$SCRIPT"
procd_set_param stderr 1
procd_close_instance
}
Problem resolved after moving /root/.ssh/known_hosts to /.ssh/known_hosts

abrt - use event to copy/move coredump to custom location

I cannot seem to find a way to configure my abrt event to copy the coredump to a custom location. The reason I want to do this is to prevent abrt from pruning my coredumps if the crash directory exceeds MaxCrashReportsSize. With the prerequisite that I have no control over how abrt is configured I would like to export the coredump to a support directory as soon as it is created.
EVENT=post-create pkg_name=raptorio analyzer=CCpp
test -f coredump && { mkdir -p /opt/raptorio/cores; cp -f coredump /opt/raptorio/cores/$(basename `cat executable`).core; }
This event will save one coredump for each C/C++ binary from my raptorio RPM package. When my program crashes abrt prints the following errors in the syslog:
Aug 30 08:28:41 abrtd: mkdir: cannot create directory `/opt/raptorio/cores': Permission denied
Aug 30 08:28:41 abrtd: cp: cannot create regular file `/opt/raptorio/cores/raptord.core': No such file or directory
Aug 30 08:28:41 abrtd: 'post-create' on '/var/spool/abrt/ccpp-2016-08-30-08:28:10-31213' exited with 1
I see that the abrt event runs as root:root but it is jailed somehow, possibly due to SELinux? I am using abrt 2.0.8 on centos 6.
/opt is not the right place to keep transient files. cores should go in /var/raptorio/cores, perhaps. See the Filesystem Hierarchy Standard
Assuming your program runs as user 'nobody', make sure 'nobody' has write permissions on that directory, and you should be all set.

How to read HD serial in Linux without root privileges?

I am building a C/C++ program which needs to read the HD serial. I am aware that if I run these commands:
hdparm -i /dev/sda | grep -i serial
/sbin/udevadm info --query=property --name=sda | grep "ID_SERIAL"
I can get it, the first requires root permissions but the second doesn't.
However, my application cannot access external programs, and it cannot require root privileges, so is there a C/C++ linux library that has a function that returns the HD serial? Or is there any other way that does not require running a program?
By just listing /dev/disk/by-id/ directory, you get IDs of all block devices on your system. The output is not exactly the same as with the commands, but it is close enough.
For this, you do not need root privileges.
On my PC :
$ /sbin/udevadm info --query=property --name=sda | grep "ID_SERIAL"
ID_SERIAL=WDC_WD5000AAKX-60U6AA0_WD-WCC2EHJ93860
ID_SERIAL_SHORT=WD-WCC2EHJ93860
and
$ ll /dev/disk/by-id/ | grep sda
lrwxrwxrwx 1 root root 9 Nov 11 07:47 ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EHJ93860 -> ../../sda
lrwxrwxrwx 1 root root 10 Nov 11 07:47 ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EHJ93860-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Nov 11 07:47 ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EHJ93860-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Nov 11 07:47 ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EHJ93860-part3 -> ../../sda3
You can use ioctls to access hard drive information, just as hdparm does. The HDIO_GET_IDENTITY ioctl should be sufficient for your needs. It returns a structure which (IIRC) includes the serial number; googling around should help you find the structure definition.

Auto run Jetty on boot

I'm trying to get Jetty to auto start on my Ubuntu.
I've done these commands:
cp /opt/jetty/bin/jetty.sh /etc/init.d
update-rc.d jetty.sh defaults
but when I run it I got a "Not starting jetty - NO_START=1 ".
Does anyone know why?
Secondly, the following is stated inside the jetty.sh.
# To get the service to restart correctly on reboot, uncomment below (3 lines):
# ========================
# chkconfig: 3 99 99
# description: Jetty 7 webserver
# processname: jetty
# ========================
What "3 lines" are they referring to? I uncommented
chkconfig: 3 99 99
description: Jetty 7 webserver
processname: jetty
but got an error too.
By default, Jetty doesn't startup by itself.
You have to modify /etc/default/jetty6 (or whereever your config file is) and set:
no_start = 0
You can do this by commenting too. #NO_START=1
It can be easily done by following steps.
In terminal type sudo vi /etc/default/jetty
In the beginning you can see a line NO_START=1
Press Insert key on your keyboard, then you can go to insert mode.
In the bottom also you can see -INSERT- to make sure that you are in insert mode.
Comment the line, #NO_START=1
Press Esc to leave the escape mode.
then type the following to save your changes and to exit. :wq!
Now you can start.

(Error in makefile)RTNETLINK answers: File exists

This is my makefile:
delay:
tc qdisc add dev eth0 root netem delay 0ms
test4_s_delay:delay
./a.out 10 10 1 2 3 1 1 20 | tee server_delay.txt
However, I am getting the following error on execution of the makefile:
root#superwii-laptop:/home/superwii/Desktop/Amogh# make test4_s_delay
tc qdisc add dev eth0 root netem delay 0ms
RTNETLINK answers: File exists
make: *** [delay] Error 2
I am unable to get past this error. Please help.
You would get this error, if qdisc root node already exists.
Try deleting the root qdisc
sudo tc qdisc del dev eth0 root
and try again
Looks like your executable tc is exiting with non-zero value of 2.
Try running the command tc qdisc add dev eth0 root netem delay 0ms and see if it runs fine.
use replace instead of add
tc qdisc replace dev eth0 root netem delay. Man page for tc says :
replace
performs a nearly atomic remove/add on an existing node id. If
the node does not exist yet it is created.