CakePHP crontab intl - cakephp

I create a crontab for execute de cakephp-queue but it returns!
You must enable the intl extension to use CakePHP
Not working: */1 * * * * MY_FULL_PATH_TO_APP && bin/cake queue runworker
I run php -m | grep intl it returns intl!
When I execute cake and make a request, it works well, but with crontab, it not works!
From crontab http request, it works well too!
Working: */1 * * * * wget http://af99d912.ngrok.io/api/v4/usuarios/checar.json
SO macOS!

Depending on your configuration, CLI and webserwer can use different php.ini files. And thats probably your case. First run: php -i | grep "Configuration File" from CLI, it should output your php.ini file location. Open it with your favourite text editor and enable intl there.

Related

How to view apps packageName with ADB commands? [duplicate]

I need to get the package name of an Android APK. I have tried to unzip the APK and read the contents of the AndroidManifest.xml file but it seems that it's not a text file.
How can I extract the APK's package name?
aapt dump badging <path-to-apk> | grep package:\ name
Install the apk on your Android device. Then
you can launch adb shell and execute pm list packages -f, which shows the package name for each installed apk.
This is taken from
Find package name for Android apps to use Intent to launch Market app from web.
Based on #hackbod answer ... but related to windows.
aapt command is located on Android\SDK\build-tools\version.
If you need more info about what is appt command (Android Asset Packaging Tool) read this https://stackoverflow.com/a/28234956/812915
The dump sub-command of aapt is used to display the values of individual elements or parts of a package:
aapt dump badging <path-to-apk>
If you want see only the line with package: name info, use findstr
aapt dump badging <path-to-apk> | findstr -n "package: name" | findstr "1:"
Hope it help other windows user!
If you are looking at google play and want to know its package name then you can look at url or address bar. You will get package name. Here com.landshark.yaum is the package name
https://play.google.com/store/apps/details?id=com.landshark.yaum&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5sYW5kc2hhcmsueWF1bSJd
The following bash script will display the package name and the main activity name:
apk_package.sh
package=$(aapt dump badging "$*" | awk '/package/{gsub("name=|'"'"'",""); print $2}')
activity=$(aapt dump badging "$*" | awk '/activity/{gsub("name=|'"'"'",""); print $2}')
echo
echo " file : $1"
echo "package : $package"
echo "activity: $activity"
run it like so:
apk_package.sh /path/to/my.apk
If you open the AndroidManifest.xml using MS Notepad, search for phrase package and you'll find following:
package manifest $xxx.xxxxxxx.xxxxxxx |
where xxx.xxxxxxx.xxxxxxx is your package name, just written with a space after each character.
It's useful way when you don't have any specific tools installed.
Since its mentioned in Android documentation that AAPT has been deprecated, getting the package name using AAPT2 command in Linux is as follows:
./aapt2 dump packagename <path_to_apk>
Since I am using an older version of Gradle build, I had to download a newer version of AAPT2 as mentioned here :
Download AAPT2 from Google Maven
Using the build-tools in my sdk - 25.0.3, 26.0.1 and 27.0.3, executing the aapt2 command shows an error: Unable to open 'packagename': No such file or directory. That's why I went for the newer versions of AAPT2.
I used 3.3.0-5013011 for linux.
A Programmatic Answer
If you need to do this programmatically, it's a little more involved than just getting the answer into your brain. I have a script that I use to sign all of our apps, but each use a different key. Here are 2 ways to get just the Package Name as output so you can put it in a variable or do whatever you need with it.
Example output: com.example.appname (and nothing more)
Requirements
aapt - Android Asset Packaging Tool, part of the SDK Tools download
Solution 1
Using awk specify ' as the Field Separator, search for a line with package: name=, and print only the 2nd "field" in the line:
aapt dump badging /path/to/file.apk | awk -v FS="'" '/package: name=/{print $2}'
A weakness of this method is that it relies on aapt to output the package information fields in the same order:
package: name='com.example.appname' versionCode='3461' versionName='2.2.4' platformBuildVersionName='4.2.2-1425461'
We have no commitments from the developers to maintain this format.
Solution 2
Using awk specify " as the Field Separator, search for a line with package=, and print only the 2nd "field" in the line:
aapt list -a /path/to/file.apk | awk -v FS='"' '/package=/{print $2}'
A weakness of this method is that it relies on aapt to output package= only in the Android Manifest: section of the output. We have no commitments from the developers to maintain this format.
Solution 3
Expand the apk file with apktool d and read the AndroidManifest.xml.
This would be the best method, but the AndroidManifest.xml is a binary file and all the SO answers I see for converting it to text do not work. (Using apktool d instead of a simple unzip is supposed to do this for you, but it does not.) Please comment if you have an solution to this issue
A simple solution would be Open Android Studio -> Build -> Analyze Apk... browse and select the APK now you can find the package name and pretty much you can read.
You can use Analyze APK... from the Build menu in Android Studio, it will display the package name at the top of new window.
If you don't have the Android SDK installed, like in some test scenarios, you can get the package name using the following bash method:
getAppIdFromApk() {
local apk_path="$1"
# regular expression (required)
local re="^\"L.*/MainActivity;"
# sed substitute expression
local se="s:^\"L\(.*\)/MainActivity;:\1:p"
# tr expression
local te=' / .';
local app_id="$(unzip -p $apk_path classes.dex | strings | grep -Eo $re | sed -n -e $se | tr $te)"
echo "$app_id"
}
Tested on a mac. 'strings' and 'unzip' are standard on most linux's, so should work on linux too.
A very simple method is to use apkanalyzer.
apkanalyzer manifest application-id "${_path_to_apk}"
On Mac:
Way 1:
zgong$ /Users/zgong/Library/Android/sdk/build-tools/29.0.3/aapt dump badging ~/Downloads/NonSIMCC-151-app-release-signed.apk
package: name='com.A.B' versionCode='2020111801' versionName='1.0.40' compileSdkVersion='29' compileSdkVersionCodename='10'
sdkVersion:'24'
targetSdkVersion:'29'
......
Way 2:
/Users/zgong/Library/Android/sdk/build-tools/29.0.3/aapt2 dump packagename ~/Downloads/NonSIMCC-151-app-release-signed.apk
com.A.B
If you just want to know package name, run adb logcat, launch the activity you want , you will get a hint on the package name.
Another solution is to use aapt list and use sed to parse through that:
aapt list -a $PATH_TO_YOUR_APK | sed -n "/^Package Group[^s]/s/.*name=//p"
I think the best and simplest way to extract only the package name in Linux is
aapt dump badging <APK_path> | grep package | sed -r "s/package: name='([a-z0-9.]*)'.*/\1/"
Explanation:
AAPT extracts the APK information
Grep "package" to keep only the line about the package information
Make sed replace the whole line with the package name only using the following regex: package: name='([a-z0-9.]*)'.* and replacing with the first (and only) matching group.
There's a very simple way if you got your APK allready on your Smartphone. Just use one of these APPs:
Package Name Viewer Apps
To use this in batch scripting it's handy to have the script return just the package name (e.g. for uninstalling an app when you have the APK).
Here's the script I use:
# extract the android package id from a built apk file
# usage ./getPackageName.sh <path-to-apk>
line=`aapt dump badging "$1" | grep package:\ name`
# above returns:
# package: name='com.calvium.myapp' versionCode='1' versionName='1.0'
if [[ $line =~ name=\'(.+)\'\ versionCode ]]; then
echo ${BASH_REMATCH[1]}
else
echo "Failed to find package name"
exit 1
fi
available on gist
So you could write:
adb uninstall `./getPackageName.sh file.apk`
You can extract AndroidManifest.xml from the APK, remove all NULL bytes, skip everything until after the string 'manifest', and then you are at a length byte followed by the package name (and what comes after it). For the difficult task I use the great GEMA tool, so the command looks like this:
7z e -so MyApp.apk AndroidManifest.xml | gema '\x00=' | gema -match 'manifest<U1><U>=#substring{0;#char-int{$1};$2}'
Of course, you can use any other tool to do the filtering.
For Windows following worked for me:
:: // Initializing variables
SET adb="C:\Users\<User name>\AppData\Local\Android\Sdk\platform-tools\adb"
SET aapt="C:\Users\<User name>\AppData\Local\Android\Sdk\build-tools\22.0.0\aapt"
SET APKPath=C:\Users\<User name>\Desktop\APK\Instant_Instal\
CD %APKPath%
:: // Searching for apk file and storing it
FOR /F "delims=" %%f IN ('dir /S /B *.apk') DO SET "APKFullPath=%%f"
SET apk=%APKFullPath%
:: // Command adb install apk, run apk
%adb% install %apk%
:: // Fetching package name from apk
%aapt% dump badging %APKFullPath% | FIND "package: name=" > temp.txt
FOR /F "tokens=2 delims='" %%s IN (temp.txt) DO SET pkgName=%%s
del temp.txt
:: // Launching apk
%adb% shell monkey -p %pkgName% -c android.intent.category.LAUNCHER 1
pause
Note
Please edit the paths of adb, aapt, APKPath according to the paths of adb, aapt, and the apk location in your system.
Working:
Here I have added the apk in a folder on Desktop "\Desktop\APK\Instant_Instal\".
The command %adb% install %apk% installs the application if the device is connected.
This %aapt% dump badging %APKFullPath% | FIND "package: name=" > temp.txt fetches package name and a few other details like version etc. of the apk and stores in a temp.txt file in same location as that of the apk.
FOR /F "tokens=2 delims='" %%s IN (temp.txt) DO SET pkgName=%%sextracts the package name and assigns topkgName` variable
Finally %adb% shell monkey -p %pkgName% -c android.intent.category.LAUNCHER 1 launches the app.
In essence the above code installs the apk from given location in desktop "Desktop\APK\Instant_Instal\" to the device and launches the application.
You can get the package name programmatically by :
packageManager.getPackageArchiveInfo(apkFilePath, 0)?.packageName
you can instal Package_Name_Viewer.apk on your emulator and next you can see package name of all instaled app on your emulator.
I also tried the de-compilation thing, it works but recently I found the easiest way:
Download and install Appium from Appium website
Open Appium->Android setting, choose the target apk file. And then you get everything you want, the package info, activity info.
As I don't was able to find the package name in the .apk file with editor (like suggested above), I have checked the functions in the App "ES Datei Explorer" / "ES File Explorer" (free version) that I had installed already.
In this tool, the package name is showed properly.
As I think a good file explorer should not be missing on a phone, I suggest to use this tool (if you already have installed the apk on an mobile and have to know the package name).
If you want to read the package name of a typical APK file in your app, there's an easy way to analyze the PackageInfo:
fun getAPKPackageName(apkFile: File?): String? {
if (apkFile == null || !apkFile.isFile || !apkFile.exists()) return null
val apkFilePath = apkFile.absolutePath
if (apkFilePath.isNullOrEmpty()) return null
val packageManager = App.context.packageManager ?: return null
val packageInfo = packageManager.getPackageArchiveInfo(apkFilePath, 0) ?: return null
return packageInfo.packageName
}

backup of database using shellscript using crontab fails?

My shellscript for taking backup of databse works fine normally.
But when i try to run through crontab there is no backup.
this is mycrontab
* * * * * /home/mohan/sohan/backuptest.sh
content of backuptest.sh are
#!/bin/bash
name=`date +%Y%m%d`.sql
#echo $name
mysqldump -u abc --password=abc my_db > $name
backup.sh works fine when normally run .But fails to generate backup when run through crontab
A couple of possibilities... first that your programs/commands cannot be found when run from cron, and second that your database cannot be found when run from cron.
So, first the programs. You are using date and mysqldump, so at youir Terminal prompt you need to find where they are located, like this:
which date
which mysqldump
Then you can either put the full paths that you get as output above into your script, or add a PATH= statement at the second line that incorporates both paths.
Secondly, your database. Where is it located? If it is in /home/mohan/sohan/ for example, you will need to change your script like this:
#!/bin/bash
name=`/bin/date +%Y%m%d`.sql
cd /home/mohan/sohan
/usr/local/bin/mysqldump -u abc --password=abc my_db > $name

How do I test a manual check in check_mk / Nagios

My organization is using Nagios with the check_mk plugin to monitor our nodes. My question is: is it possible run a manual check from the command line? It is important, process-wise, to be able to test a configuration change before deploying it.
For example, I've prepared a configuration change which uses the ps.perf check type to check the number of httpd processes on our web servers. The check looks like this:
checks = [
( ["web"], ALL_HOSTS, "ps.perf", "Number of httpd processes", ( "/usr/sbin/httpd", 1, 2, 80, 100 ) )
]
I would like to test this configuration change before committing and deploying it.
Is it possible to run this check via the command line, without first adding it to main.mk? I'm envisioning something like:
useful_program -H my.web.node -c ps.perf -A /usr/sbin/httpd,1,2,80,100
I don't see any way to do something like this in the check_mk documentation, but am hoping there is a way to achieve something like this.
Thanks!
that is easy to check.
Just make your config changes and then run:
cmk -nv HOSTNAME.
That (-n) will try run everything and return (-v) the output.
So can see the same results like later in the GUI.
List the check
$check_mk -L | grep ps.perf
if it listing ps.perf then run following command,
$check_mk --checks=ps.perf -I Hostname

Facing a file permission error while running CakePHP in Ubuntu 10.4

I have installed CakePHP 2.0 framwork using steps below:
1. Start the terminal
2. sudo mkdir /var/www/cakephp
3.sudo cp -r ~/cakephp/* /var/www/cakephp
Change tmp folder permisssion
4. sudo chmod -R 777 cakephp/app/tmp
Enable mod-rewrite
5. sudo a2enmod rewrite
Open file /etc/apache2/sites-enabled/000-default and change AllowOverride None to AllowOverride All
6. sudo vim /etc/apache2/sites-enabled/000-default
Restart Apache
7. sudo /etc/init.d/apache2 restart
I opened my browser and typed address http://localhost/cakephp/ and I seaw this error message:
Warning: _cake_core_ cache was unable to write 'cake_dev_en-us' to File cache in /var/www
/cakephp/lib/Cake/Cache/Cache.php on line 310
Warning: _cake_core_ cache was unable to
write 'cake_dev_en-us' to File cache in /var/www/cakephp/lib/Cake/Cache/Cache.php on line 310
Warning: /var/www/cakephp/app/tmp/cache/persistent/ is not writable in /var/www/cakephp
/lib/Cake/Cache/Engine/FileEngine.php on line 320
Warning: /var/www/cakephp/app/tmp/cache
/models/ is not writable in /var/www/cakephp/lib/Cake/Cache/Engine/FileEngine.php on line 320
Warning: /var/www/cakephp/app/tmp/cache/ is not writable in /var/www/cakephp/lib/Cake
/Cache/Engine/FileEngine.php on line 320
The command sudo chmod -R 777 cakephp/app/tmp only made tmp writable, you should make cache and it's subdirectories writable as well, otherwise Cake can't write the cache files to the cache directory in tmp.
So, these directories should be writable:
cakephp/app/tmp/cache
cakephp/app/tmp/cache/persistent
cakephp/app/tmp/cache/models
Make sure the log directory is writable as well: cakephp/app/tmp/logs.
I've faced similar problems. Here are a couple of things that helped me:
If you don't want to use the "sledgehammer" approach of chmod 777 (you may want to avoid it on production, for instance), the CakePHP installation instructions provide details on how to use ACL instead:
For Cake 2: http://book.cakephp.org/2.0/en/installation.html#permissions
For Cake 3: http://book.cakephp.org/3.0/en/installation.html#permissions
Note that you'll probably need to use sudo for the setfacl commands given there.
However, in my experience (CakePHP 2), those commands aren't enough. These commands give your webserver user access to the cache etc, but anything you run from the command line (like the cake command) will probably be running as your user rather than the webserver user.
Therefore, you should run the setfacl commands linked to above a second time, replacing ${HTTPDUSER} with your user name. If you're not sure what your username is, type whoami to find it.
I have encountered a very similar problem with cachePhp 3.
Warning (512): /cache/persistent/ is not writable [CORE/src/Cache/Engine/FileEngine.php, line 439]
Warning (512): Cache engine Cake\Cache\Engine\FileEngine is not properly configured. [CORE/src/Cache/Cache.php, line 177]
Because I am new in CakePhp, I have debuged the file with problem - CORE/src/Cache/Engine/FileEngine.php.
Here is function like next:
protected function _active()
{
$dir = new SplFileInfo($this->_config['path']);
$path = $dir->getPathname();
$success = true;
if (!is_dir($path)) {
//#codingStandardsIgnoreStart
$success = #mkdir($path, 0775, true);
//#codingStandardsIgnoreEnd
}
$isWritableDir = ($dir->isDir() && $dir->isWritable());
if (!$success || ($this->_init && !$isWritableDir)) {
$this->_init = false;
trigger_error(sprintf(
'%s is not writable',
$this->_config['path']
), E_USER_WARNING);
}
return $success;
}
It checks if cache directory is writable and get data about path form $this->_config['path'] variable. This variable is initialized by default from .env file (if you use it), and it has lines like next:
export CACHE_DEFAULT_URL="File://tmp/cache/?prefix=${APP_NAME}_default&duration=${CACHE_DURATION}"
export CACHE_CAKECORE_URL="File://tmp/cache/persistent?prefix=${APP_NAME}_cake_core&serialize=true&duration=${CACHE_DURATION}"
export CACHE_CAKEMODEL_URL="File://tmp/cache/models?prefix=${APP_NAME}_cake_model&serialize=true&duration=${CACHE_DURATION}"
I have changed all File: to Null:, like next:
export CACHE_DEFAULT_URL="Null://tmp/cache/?prefix=${APP_NAME}_default&duration=${CACHE_DURATION}"
export CACHE_CAKECORE_URL="Null://tmp/cache/persistent?prefix=${APP_NAME}_cake_core&serialize=true&duration=${CACHE_DURATION}"
export CACHE_CAKEMODEL_URL="Null://tmp/cache/models?prefix=${APP_NAME}_cake_model&serialize=true&duration=${CACHE_DURATION}"
export CACHE_DRV_DEFLT = "Null"
export CACHE_DRV_MODEL = "Null"
export CACHE_DRV_CORE = "Null"
And it helps, my problem was fixed. Probably it will be helpfull for someone. Enjoy!
Using chmod -R 777 /var/www/cakephp/app/tmp/ i.e. making folder execuatble will solve this issue.
I even faced similar issue while testing cron i.e. shell which exists in app/Console/Command/ folder. When we execute a cron multiple time, tmp/ folder permission is overwritten and permission error will come in picture at this point which can be avoided by making tmp/ folder executable recursively.
As a temporary fix, if you want to use the provided .env file and permissions did not solve your issue modify the .env file to use absolute path that points to your app directory
export CACHE_FOLDER="/var/www/absolute_path_to_my_cakephp_app/"
export CACHE_DURATION="+2 minutes"
export CACHE_DEFAULT_URL="file://${CACHE_FOLDER}tmp/cache/?prefix=${APP_NAME}_default&duration=${CACHE_DURATION}"
export CACHE_CAKECORE_URL="file://${CACHE_FOLDER}tmp/cache/persistent?prefix=${APP_NAME}_cake_core&serialize=true&duration=${CACHE_DURATION}"
export CACHE_CAKEMODEL_URL="file://${CACHE_FOLDER}tmp/cache/models?prefix=${APP_NAME}_cake_model&serialize=true&duration=${CACHE_DURATION}"
“chmod -R 777 tmp/cache” if tmp folder is not exists then create tmp file using mkdir tmp and mkdir tmp/cache
chmod -R 777 logs
chmod -R 777 tmp/sessions
chmod -R 777 tmp/tests
chcon -R -t httpd_sys_content_rw_t 'tmp'
chcon -R -t httpd_sys_content_rw_t 'logs'

Using Cron with Cake Console on Ubuntu

I need this cron job to execute my shell just as it does when I run it on the command line.
I read through the one other question I found about this, but my console-based cron job still is not working. I want to post some code and what it outputs, maybe someone can tell me what's going on.
First off, this is on Cake 1.3. I am running on Ubuntu 9.10. I have tried the shell-script method described in the Cake Book.
I have NOT established any special user account for running the script. The cake console is on my PATH (for the ubuntu built-in user).
In another question I found, they report that the -app parameter isn't doing anything. This seems to be the case for me as well.
My shell works as it should when I run this from the command line:
./vendors/cakeshell subscription_reminder -cli /usr/bin -app /var/www/www.example.org/htdocs/app -console /var/www/www.example.org/htdocs/cake/console/cake
the output from this looks like:
Welcome to CakePHP v1.3.2 Console
---------------------------------------------------------------
App : app
Path: /var/www/www.directory.sdcweb.org/htdocs/app
---------------------------------------------------------------
I'm logging my cron-job output to a file and the output of that looks different, like this:
EDIT: i've noticed that this following code block is just the cake shell script that comes with CakePHP, if you open up cake/console/cake in a text editor you should find the following script.
################################################################################
#
# Bake is a shell script for running CakePHP bake script
# PHP versions 4 and 5
#
# CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
# Copyright 2005-2010, Cake Software Foundation, Inc.
#
# Licensed under The MIT License
# Redistributions of files must retain the above copyright notice.
#
# #copyright Copyright 2005-2010, Cake Software Foundation, Inc.
# #link http://cakephp.org CakePHP(tm) Project
# #package cake
# #subpackage cake.cake.console
# #since CakePHP(tm) v 1.2.0.5012
# #license MIT License (http://www.opensource.org/licenses/mit-license.php)
#
################################################################################
LIB=${0/%cake/}
APP=`pwd`
exec php -q ${LIB}cake.php -working "${APP}" "$#"
exit;
My crontab looks like this:
41 20 * * * /var/www/www.example.org/htdocs/app/vendors/cakeshell subscription_reminder -cli /usr/bin -app /var/www/www.example.org/htdocs/app -console /var/www/www.example.org/htdocs/cake/console/cake >> /home/ubuntu/cron-log
First of all, your cronjob runs the script with a different cwd, which may affect behavior. Change it to
41 20 * * * cd /var/www/www.example.org/htdocs/app/; ./vendors/cakeshell ....
But maybe there's something else:
The "cakephp console", cakeshell, probably checks if it's stdin is connected to a tty. If not, it goes in some other, non-interactive mode.
The point is that some programs can talk to you in a terminal (a tty) and others can't.
Some can do both, depending on circumstances.
grep is typically non-interactive
vi, pico and nano are typically only used interactively:
$ vi > test3
Vim: Warning: Output is not to a terminal
$ echo bla | vi
Vim: Warning: Input is not from a terminal
$ vi < test3
Vim: Warning: Input is not from a terminal
bash can do both (non-interactive when running scripts, interactive when serving you in a terminal)
So there's at least the answer as to why the exact same command and environment, can give totally different output. Try to start it from the commandline as you did, but redirecting input from either a pipe or a file, and see what changes.
Well, after a bit more work on this I finally arrived at a crontab which does what I want. It looks like this:
35 01 * * * cd /var/www/www.example.org/htdocs/app; ../cake/console/cake subscription_reminder
Not only does it work, but it is also a lot more readable.
Does your cakeshell begin with
#!/bin/bash
As per the example on http://book.cakephp.org/view/1110/Running-Shells-as-cronjobs?

Resources