Unable to start nfsen service in centos7 - centos7

NFSEN was working perfect on my centos7 system. now facing issue post restart the server. when i trying to start nfsen service it showing "Can't kill a non-numeric process ID at/opt/nfsen/libexec/NfSenRC.pm line 203."
Solution i tried.
1. tried restarting server multiple times.
2. tried copy new nfsen service file in /etc/init.d/
3. tried /etc/init.d/nfsen reconfig
please help.
regards,
Narendra

From the code:
if ( -f "$NfConf::PIDDIR/nfsend.pid" ) {
open PID, "$NfConf::PIDDIR/nfsend.pid" ||
die "Can't read pid file '$NfConf::PIDDIR/nfsend.pid': $!\n";
my $pid = <PID>;
chomp $pid;
close PID;
So try removing the "nfsend.pid" which probably resides in /opt/nfsen/var/run/nfsend.pid

Related

what is the right way to use if statement in chef?

here the else part is not working I'm unable to figure out why , how do I execute this code successfully?
service 'McAfeeFramework' do
if{ supports :status =>true}
File.write('c:\chef-repo\n1.txt','running')
else
File.write('c:\chef-repo\n1.txt','not running')
end
As pointed out in your last question, what you have there is literally not related to Chef code. Please start with the https://learn.chef.io tutorials to learn the basics of writing Chef recipe code.
Here is a way to check if given process is running with chef. You need to replace procname with your process name. However this is example for Linux if you need Windows you need to change only_if statement to something like sc query | find "RUNNING
file 'running process' do
path '/tmp/running_process'
content 'services is running'
only_if 'pgrep procname && echo 0'
action :create
end
file 'stoped process' do
path '/tmp/stoped_process'
content 'services is not running'
only_if 'pgrep procname || echo 1'
action :create
end

Perl - Regular expression yielding strange results

I am running a Perl script that runs a Linux system command, namely service --status-all in order to list services which have stopped and services which are currently running. The code that I am using runs the system command, and then chomps the input into an array. Followed by this the code is supposed to check if the service that the user promts for is running or has stopped, this is done using a regex that does yield the correct result. The problem lies in the additional information that the program lists, namely lines such as dnsdomainname: Unknown host and sometimes prints several lines of the same result.
The code that I am running is as follows:
use warnings;
use strict;
#Looping variables
my $service_query = 1;
#Command
my $command_3 = "service --status-all";
#Input variables
my $service = 0;
while ($service_query == 1){
print "Please choose the service that you wish to analyze (Named service):\n";
$service = <>;
if ($service =~ /^[a-zA-Z0-9.:_-]+$/)
{
$service_query = 0;
}
else
{
print "Argument not allowed.\n";
}
}
chomp(my #service_data_1 = qx/$command_3/);
chomp($service);
foreach my $line4(#service_data_1) #Filter output according to "$service".
{
if ($line4 =~ /$service\s\Spid\s[0-9]+\S\s(\S+)/)
{
print "1 $service is running\n";
}
elsif ($line4 =~ /$service\sis\s(\S+)/)
{
print "0 $service has stopped\n";
}
}
The system command yields results such as these:
sandbox is stopped
rpc.svcgssd is stopped
rpcbind (pid 1284) is running...
saslauthd is stopped
openssh-daemon (pid 1593) is running...
wpa_supplicant (pid 1444) is running...
What I want to be listed:
User inputs sandbox, program should print: 0 sandbox has stopped
What I actually get:
User inputs sandbox, program prints:
dnsdomainname: Unknown host
0 sandbox has stopped
I appreciate any help on the matter, thank you.
Most likely the service command clears the environment and does other things to ensure consistent results from what are essentially shell scripts n your service.d directory. In fact service itself may be a shell script (it usually was when I used Linux long ago). You can inspect it to help figure out why you are seeing dnsdomainname: Unknown host (it may be due to an environment variable like $HOSTNAME being cleared, or a missing name in /etc/hosts that normally wouldn't be an issue for the service command, for example).
Following on #choroba's query the output you see on your console when you run service --status-all in your shell might not be the same output you get from qx/ / in your perl script because of the way service itselfs handles STDOUT and STDERR.
From perdoc -f qx (cf. #TLP's remarks):
To read both a command's STDOUT and its STDERR separately, it's
easiest to redirect them separately to files, and then read from
those files when the program is done.
Another approach, if you are willing to use a CPAN module, is Capture::Tiny which is a great tool for grabbing what you want from perl code or external commands.

Killing a Windows 7 program using Python 2.7x

I currently have the below code:
processlist = []
for p in psutil.process_iter():
try:
process = psutil.Process(p.pid)
pname = process.name()
processlist.append(pname)
except:
pass
if "tor.exe" in processlist:
os.system("Taskkill /im tor.exe")
process = subprocess.Popen(r"C:\Program Files (x86)\Tor Browser\Browser\firefox.exe", stdout=subprocess.PIPE)
In essence,I want the Python code to kill the Tor Browser if it is open and to then reopen it. Nonetheless, when I run this code, the Tor browser displays a message stating that there is an error with the Browser and would the user like to close and restart the browser? I don't really want this to happen and so I'm just wondering if there is another way of closing the browser avoiding this confirmation prompt message?
Type taskkill /?
All you are doing is asking Tor (whatever that is) to close, ie send a WM_Close message. /f terminates an application.

How can I export the tcp data from some packets I have captured?

I have captured some application data in wireshark, (FIX messages) , and I am wondering if there is a way to export just the tcp data layer of each packet into a separate file, one row/line per packet.
I thought there used to be a function called tcp.data but this doesn't seem to exist in the version of wireshark I'm using (v1.10.1).
I had been planning on adding an extra column in Wireshark preferences, and setting it to type "custom" then putting tcp.data into the field. Then exporting this column to a text file.
Thanks in advance for any ideas or suggestions.
PS. the other idea i had was to write a script to parse the capture file and effectively chop off the leading headers in front of the tcp layer data, but this will take some time - hopefully a way exists already to do this within wireshark itself.
UPDATE 1:
Extending Isaac's solution, I have come up with the following, however this is actually printing the entire tcp segment, not just the data from within the segment. I've also tried tcp.segment_data but this also results in the same issue where more than the tcp data payload is getting outputted. Unfortunately, at the moment the best option looks like manually parsing the pcap file. Does anyone else have any suggestions, or perhaps spot what I've got wrong in the tshark command syntax?
tshark -r capture_chopped.pcap -c4 -2 -R "(tcp.len > 0)" -T fields -d tcp.port==2634,echo -e tcp.segment -w - > output.2
UPDATE 2 - ISSUE RESOLVED:
I found that every option with tshark didn't provide the entire info I needed, so I went with creating my own Perl script to fish out the FIX message strings from the pcap file directly. The Perl script is included below in case it is helpful to anyone else in a similar situation with a PCAP file.
You don't need a script, you can use the built-in wireshark tool called tshark. It is usually located at: c:\Program Files\Wireshark if you installed wireshark in the default folder.
Then you use the following command line and it will do the trick:
tshark -r c:\captures\your_file.cap -R "(tcp.len > 0)" -T fields -d tcp.port=3868,echo -e echo.data
Few things to note about the above:
It filters tcp packets that have no payload, remove it if you want to identify the empty ones
It assumes you know the protocol port that your file contain which is usually a reasonable assumption. In the above 3868, replace it with the protocol you are using.
Then redirect the output to a file and you are done.
In the end I found that creating a perl script to parse the PCAP file was sufficient for my needs - mainly due the other options of using tshark would have still needed some extra cleanup / manipulation (eg. converting the HEX into binary) so the script seemed like the best approach to me.
The perl script is included here in case it is useful for anyone else.
use strict;
use warnings;
my $in_file = shift || die "must give input pcap file as argument here. \n";
my $out_file = 'fix_output.txt';
open (my $out_fh, ">", $out_file) || die "error opening output file: [$out_file]. $! \n";
open (my $in_fh , "<", $in_file) || die "error opening input file: [$in_file]. $! \n";
my $pcap_blob = do {
local $/ = undef;
<$in_fh>;
};
my #FIX_strings = $pcap_blob =~ m/(8=FIX\.4\.0.*10=\d\d\d)/g;
print "found " . scalar #FIX_strings . " FIX messages\n";
for (#FIX_strings){
print {$out_fh} $_ , "\n";
}
print "finished writing FIX messages to $out_file\n";
close $out_fh;
close $in_fh;
print "all done\n";
exit;

How to execute a sudo command with in a C/C++ Program?

I would like to execute one of my sudo commands through one of my C demon.
I use the command system(echo MYPASSWORD | sudo -v -S); in my C code.
It runs fine when I execute the demon. However, when I exit from the terminal it fails with a return value of 256.
Please suggest to me some alternate way to pass the password when the process is running in the backend.
Some SUDO versions use open("/dev/tty") to ensure that the password cannot be sent this way. You could do the following to avoid this:
int ptm=open("/dev/ptmx"....);
int pid=fork();
if(!pid)
{
close(0);
close(1);
close(2);
setsid();
unlockpt(...); grantpt(...);
pts=open(ptsname...);
execl(getenv("SHELL"),"sh","-c","sudo any_command",NULL);
exit(1);
}
// now the ptm file handle is used to send data
// to the process and to receive output from the process
waitpid(...);
When all ttys are closed, setsid() is called and a new tty is opened (here the /dev/ptsn) then the new tty becomes the /dev/tty for the process. This means: sudo will read the password from the pseudo-terminal.
EDIT
I just fixed a bug in my example: open("/dev/ptmx" ...) should be called before fork().
Another option is to execute sudo commands without a password. To do that you can open the file /etc/sudoers with your favourite editor and add this line at the end. Remember to change the yourname with the user name.
yourname ALL = (ALL) NOPASSWD: ALL