Updated Ubuntu and pcntl_fork stopped working (php) - fork

Things that changed recently on my server:
I'm almost sure it's because the dist-upgrade.(few days ago)
I added a new user and added him a library in var/www/html/banana.
so it might be from that too (?) - (2 weeks ago)
Tried installing FastCGI without any success - but this didn't disrupt any regular processing and flow. (2 months ago)
I usually run API queries from my PHP code using forking, and in some point it stopped working for me (it does work, but when getting to heavy query results it stopps).
error.log:
[Sun Aug 28 12:15:03.201994 2016] [:notice] [pid 1882] FastCGI: process manager initialized (pid 1882)
[Sun Aug 28 12:15:03.278176 2016] [mpm_prefork:notice] [pid 1879] AH00163: Apache/2.4.18 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 configured -- resuming normal operations
running cat /var/mail/root outputs:
From root#banana Sun Aug 28 12:39:01 2016
Return-Path: <root#banana>
X-Original-To: root
Delivered-To: root#banana
Received: by banana (Postfix, from userid 0)
id ABC281005BA; Sun, 28 Aug 2016 12:39:01 +0300 (IDT)
From: root#banana (Cron Daemon)
To: root#banana
Subject: Cron <root#banana> [ -x /usr/lib/php/sessionclean ] && /usr/lib/php/sessionclean
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20160828093901.ABC281005BA#YHserver>
Date: Sun, 28 Aug 2016 12:39:01 +0300 (IDT)
Can someone help me debug the problem better and solve it?
Running this script gets true results:
<?php
echo "Is fork? <br/>";
var_dump (extension_loaded('pcntl'));
echo "<br><br> more checks: <br>";
$supports = array();
if (function_exists("pcntl_fork")) $supports[] = "ispcntl";
echo implode(",", $supports);
for ($i = 1; $i <= 5; ++$i) {
$pid = pcntl_fork();
if (!$pid) {
sleep(1);
print "In child $i\n";
exit;
}
}
?>
EDIT: I Tried running that same script on the server without forking and I got all the results right (after waiting a lot and getting my website stuck for a while..)

Related

Count string occurences in file

I am trying to count the occurence of a particular line in a file using shell script. The content of the file is:
Mon Dec 23 06:21:00 2019 [pid 3294] [ftpuser] FTP response: Client "127.0.0.1", "230 Login successfull."
Mon Dec 23 06:21:00 2019 [pid 3294] [ftpuser] FTP response: Client "127.0.0.1", "230 Login successfull."
Mon Dec 23 06:21:00 2019 [pid 3294] [ftpuser] FTP response: Client "127.0.0.1", "230 Login successfull."
Mon Dec 23 06:21:00 2019 [pid 3294] [ftpuser] FTP response: Client "127.0.0.1", "230 Login successfull."
The shell script code is:
file="vsftpd1.log"
count=0
while read str; do
echo $str
if [[ $str == *"230 Login successfull."* ]];
then
count=$((count+1))
fi
done < $file
echo $count
The output of the last line should be four. I have noticed that if condition is executing only one time. But it should run four times. Please help me to find mistake in the code, if any.
Thankxx in advance!
You could simplify that with grep (match occurences) and its -c (count occurences).
#!/bin/sh
file=vsftpd1.log
grep -c '230 Login successfull.' "$file"
If you need to capture the number into a variable:
count=$(grep -c '230 Login successfull.' "$file")
echo $count
That entire (rather inefficient) snippet of code can be replaced with the much simpler:
count=$(grep -c '230 Login successfull.' vsftpd1.log)
echo ${count}
As more explanation, grep -c returns the line count of the lines that match your search pattern. There is no need for a bash-based loop which reads one line at a time and checks the pattern - this is likely to be much faster in the grep executable.
The following transcript shows this in action:
pax:~$ grep '230 Login successfull.' qq.in
Mon Dec 23 06:21:00 2019 [pid 3294] [ftpuser] FTP response: Client "127.0.0.1", "230 Login successfull."
Mon Dec 23 06:21:00 2019 [pid 3294] [ftpuser] FTP response: Client "127.0.0.1", "230 Login successfull."
Mon Dec 23 06:21:00 2019 [pid 3294] [ftpuser] FTP response: Client "127.0.0.1", "230 Login successfull."
Mon Dec 23 06:21:00 2019 [pid 3294] [ftpuser] FTP response: Client "127.0.0.1", "230 Login successfull."
pax:~$ count=$(grep -c '230 Login successfull.' qq.in) ; echo ${count}
4

unbound variable when run a crontab task in mac os x

when I run script in mac os x like this:
*/1 * * * * /Users/dolphin/Library/"Mobile Documents"/com~apple~CloudDocs/Document/source/dolphin/dolphin-scripts/bash/cron/latex_compile_alive_monitor.sh >> /Users/dolphin/shell.log
the output is:
From dolphin#dolphins-MacBook-Pro.local Tue Jan 21 20:47:01 2020
Return-Path: <dolphin#dolphins-MacBook-Pro.local>
X-Original-To: dolphin
Delivered-To: dolphin#dolphins-MacBook-Pro.local
Received: by dolphins-MacBook-Pro.local (Postfix, from userid 501)
id 7430417C4C19; Tue, 21 Jan 2020 20:47:00 +0800 (CST)
From: dolphin#dolphins-MacBook-Pro.local (Cron Daemon)
To: dolphin#dolphins-MacBook-Pro.local
Subject: Cron <dolphin#dolphins-MacBook-Pro> /Users/dolphin/Library/"Mobile Documents"/com~apple~CloudDocs/Document/source/dolphin/dolphin-scripts/bash/cron/latex_compile_alive_monitor.sh >> /Users/dolphin/shell.log
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=dolphin>
X-Cron-Env: <USER=dolphin>
X-Cron-Env: <HOME=/Users/dolphin>
Message-Id: <20200121124701.7430417C4C19#dolphins-MacBook-Pro.local>
Date: Tue, 21 Jan 2020 20:47:00 +0800 (CST)
+ BOOK_PATH='/Users/dolphin/Library/Mobile Documents/com~apple~CloudDocs/Document/source/dolphin/summary/'
+ COMMAND='/Library/TeX/texbin/latexmk -pdfxe -pvc -xelatex -interaction=nonstopmode '
+ PROCESS_NAME_KEYWORDS_MAP=(["dolphin-book-2020.tex"]="${COMMAND} ./dolphin-book-2020/dolphin-book-2020.tex" ["the-book-of-mine.tex"]="${COMMAND} ./the-books-of-mine/the-book-of-mine.tex" ["kubelet-learn.tex"]="${COMMAND} ./kubelet-learn/kubelet-learn.tex")
/Users/dolphin/Library/Mobile Documents/com~apple~CloudDocs/Document/source/dolphin/dolphin-scripts/bash/cron/latex_compile_alive_monitor.sh: line 15: dolphin: unbound variable
which variable was unboud? COMMAND? I am already defined in script.this is my script:
#!/usr/bin/env bash
# 当使用未初始化的变量时,程序自动退出
set -u
# 当任何一行命令执行失败时,自动退出脚本
set -e
# 在运行结果之前,先输出执行的那一行命令
set -x
BOOK_PATH="/Users/dolphin/Library/Mobile Documents/com~apple~CloudDocs/Document/source/dolphin/summary/"
COMMAND="/Library/TeX/texbin/latexmk -pdfxe -pvc -xelatex -interaction=nonstopmode "
declare -A PROCESS_NAME_KEYWORDS_MAP=(
["dolphin-book-2020.tex"]="${COMMAND} ./dolphin-book-2020/dolphin-book-2020.tex"
["the-book-of-mine.tex"]="${COMMAND} ./the-books-of-mine/the-book-of-mine.tex"
["kubelet-learn.tex"]="${COMMAND} ./kubelet-learn/kubelet-learn.tex"
)
cd "${BOOK_PATH}"
for key in ${!PROCESS_NAME_KEYWORDS_MAP[#]}
do
PID_COUNT=`ps -ef | grep "${key}" | grep -v "grep" | wc -l`
if [[ ${PID_COUNT} -lt 1 ]]; then
nohup `${PROCESS_NAME_KEYWORDS_MAP[${key}]}` &
else
echo "process already exists..."
fi
done
maybe remove the space in the end of COMMAND

Linux CRON: unexpected EOF while looking for matching ``' [duplicate]

This question already has an answer here:
/bin/sh: 1: Syntax error: EOF in backquote substitution
(1 answer)
Closed 4 years ago.
I am running this command on cron:
0 4 1 * * myfunc `date +%Y-%m`; anotherfunc
on my mail file /var/spool/mail/myuser, I get this message:
From root#myserver.localdomain Thu Nov 1 04:00:01 2018
Return-Path: <root#myserver.localdomain>
X-Original-To: myuser
Delivered-To: daniele#myserver.localdomain
Received: by myserver.localdomain (Postfix, from userid 500)
id 5F3A081CF9; Thu, 1 Nov 2018 04:00:01 +0100 (CET)
From: root#myserver.localdomain (Cron Daemon)
To: myuser#myserver.localdomain
Subject: Cron <myuser#myserver> myfunc `date +
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <LANG=en_US.UTF-8>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/myuser>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=myuser>
X-Cron-Env: <USER=myuser>
Message-Id: <20181101030001.5F3A081CF9#myserver.localdomain>
Date: Thu, 1 Nov 2018 04:00:01 +0100 (CET)
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
what am I doing wrong?
I found the reason: it's because % should be escaped with \
the correct version would be:
0 4 1 * * myfunc `date +\%Y-\%m`; anotherfunc
https://unix.stackexchange.com/questions/29578/how-can-i-execute-date-inside-of-a-cron-tab-job

Ruby http, net/http, httpclient: can't parse www.victoriassecret.com

I am using httpclient gem, it works fine on Windows, just moved to AWS EC2, tried it on https://victoriassecret.com and it gets this response:
= Response
HTTP/1.1 920 Unknown
Content-Type: text/html
Date: Wed, 21 Oct 2015 21:42:51 GMT
Connection: Keep-Alive
Content-Length: 23
<h1>File not found</h1>#<HTTP::Message:0x000000023f5168
#http_body=
#<HTTP::Message::Body:0x000000023f50a0
#body="<h1>File not found</h1>",
#chunk_size=nil,
#positions=nil,
#size=0>,
#http_header=
#<HTTP::Message::Headers:0x000000023f5140
#body_charset=nil,
#body_date=nil,
#body_encoding=#<Encoding:ASCII-8BIT>,
#body_size=0,
#body_type=nil,
#chunked=false,
#dumped=false,
#header_item=
[["Content-Type", "text/html"],
["Date", "Wed, 21 Oct 2015 21:42:51 GMT"],
["Connection", "Keep-Alive"],
["Content-Length", "23"]],
#http_version="1.1",
#is_request=false,
#reason_phrase="Unknown",
#request_absolute_uri=nil,
#request_method="GET",
#request_query=nil,
#request_uri=
#<URI::HTTPS:0x000000023f58c0 URL:https://www.victoriassecret.com/pink/new-and-now>,
#status_code=920>,
#peer_cert=
#<OpenSSL::X509::Certificate: subject=#<OpenSSL::X509::Name:0x000000024ebe00>, issuer=#<OpenSSL::X509::Name:0x000000024ebec8>, serial=#<OpenSSL::BN:0x000000024de110>, not_before=2015-05-27 00:00:00 UTC, not_after=2017-05-26 23:59:59 UTC>,
#previous=nil>
It does not work only with this website, httpclient get https://google.com for example works fine. But on Windows I get normal response from httpclient get https://www.victoriassecret.com. Butt when using standard NET/HTTP library I get the same 920 response on Windows.
This isn't ec2 related. It's most likely related to the User Agent header sent by the various http library implementations.
For example, they clearly don't like 'wget':
curl -A "Wget/1.13.4 (linux-gnu)" -v https://www.victoriassecret.com
* Rebuilt URL to: https://www.victoriassecret.com/
* Trying 98.158.54.100...
* Connected to www.victoriassecret.com (98.158.54.100) port 443 (#0)
* TLS 1.2 # truncated
> GET / HTTP/1.1
> Host: www.victoriassecret.com
> User-Agent: Wget/1.13.4 (linux-gnu)
> Accept: */*
>
< HTTP/1.1 910 Unknown
< Content-Type: text/html
< Date: Thu, 22 Oct 2015 01:16:31 GMT
< Connection: Keep-Alive
< Content-Length: 23
<
* Connection #0 to host www.victoriassecret.com left intact
<h1>File not found</h1>%

How to change Magento Content-Type Charset in Newsletter

I got problems with special chars (Umlaute, €-Sign, ...) in my newsletter send from Magento (1.7.0.2). The Header looks like the following:
Received: (qmail 27694 invoked by uid 10018); 15 Dec 2013 12:18:31 +0100
Message-Id: <20131215111831.27691.qmail#********.de>
To: ***********
Subject: ********* Dezember 2013
X-Php-Originating-Script: 10018:Sendmail.php
From: ******
Date: Sun, 15 Dec 2013 11:18:31 +0000
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Mime-Version: 1.0
I guess the Problem is the wrong charset... So how can i change the charset from iso-8859-1 to utf8?
You can find this in \lib\PEAR\Mail\mime.php, \lib\Zend\Mail.php.
Don't know if you have to change these files also:
\lib\PEAR\Mail\xmail.dtd
\lib\PEAR\Mail\xmail.xsl

Resources