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?
Related
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.
I used to have a server running CentOS, and I used to execute shell files this way:
sudo sh /folder/script.sh
Now I have an Ubuntu server. When I'm executing the same command line, I now have the following error message:
/folder/script.sh: ID[0]=ID: not found
I had a look on the internet and it says I need to use:
sudo /bin/bash /folder/script.sh
But when I do so I got the same error message.
The first line of my script is:
ID[0]="ID"
/bin/sh is often a POSIX shell, which does not support arrays.
I suggest you install another shell which does support them, like mksh (disclaimer: I’m its developer), ksh93, zsh, or just use GNU bash instead, and call your script with, for example, sudo mksh /folder/script.sh instead. This will give you more consistent behaviour across systems, too (note that to behave consistent on all platforms is actually an mksh design goal).
Hm… this works for me:
$ cat >x
#!/bin/bash
ID[0]="ID"
echo works for me
$ mksh x
works for me
Do you have any weird characters in your script, like embedded Carriage Return (^M)? Check with: cat -v /folder/script.sh
how can I make my C code to auto-run on my Raspberry PI? I have seen a tutorial so as to achieve that but I do not really know what I am still missing. My initialization script is shown as it follows:
#! /bin/sh
# /etc/init.d/my_settings
#
# Something that could run always can be written here
### BEGIN INIT INFO
# Provides: my_settings
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Script to start C program at boot time
# Description: Enable service provided by my_settings
### END INIT INFO
# Carry out different functions when asked to by the system
case "$1" in
start)
echo "Starting RPi Data Collector Program"
# run application you want to start
sudo /home/pi/Documents/C_Projects/cfor_RPi/charlie &
;;
stop)
echo "Killing RPi Data Collector Program"
# kills the application you want to stop
sudo killall charlie
;;
*)
echo "Usage: /etc/init.d/my_settings {start | stop}"
exit 1
;;
esac
exit 0
The problem is that my program does not run at boot time and I do not really know why. What would I be missing? Is this "killall" statement "killing" some useful process during execution time? I am making this code to run as a background application but I know that after a few seconds, when the RPi is initializing, it asks for an username and a password in order to initialize the session. Is it possible that my RPi is not executing this code because I am not providing the logging information? I do not have a monitor so that my program has to run once I plug my Rpi in. Thanks a lot in advance!!
You'll have to create links to that init script in the proper /etc/rcX.d folders. On raspbian this is done by:
sudo update-rc.d YOUR_INIT_SCRIPT_NAME defaults
You can read this debian how-to for further information. Also you should read more about run levels in Debian.
How scripts/services are run at startuptime, generally depends on the type of init system used. Off the top of my head, I'd distginguish the following 4 types:
Embedded style: A single shell script has all the commands to start the system. Usually the script is at one off the paths the kernel tries to start as init process.
BSD style
System V style: This uses /etc/inittab and latr scripts in /etc/rc*.d/ to start services one by one
systemd
Raspbian dervices from Debian, so I suppose System V style. You have to symlink your script to /etc/rc2.d like
ln -s /etc/init.d/your-script /etc/rc2.d/S08my-script
Not the structure of the link name: It says, it should be started when the run level is entered, and the '08' determines the position (do a ls /etc/rc2.d/ to see the other links).
More details: init(8).
update-rc.d(8) is the proper wway to create the symlinks on debian. See the manpage:
update-rc.d - install and remove System-V style init script links
I advice to read at least the man pages update-rc.d(8) and init(8).
http://www.akeric.com/blog/?p=1976
Here a tutorial on how to auto-loggin and start a script at boot.
If it still don t work, there s either a problem in your script or in your C program.
This is the process we perform manually.
$ sudo su - gvr
[gvr/DB:DEV3FXCU]/home/gvr>
$ ai_dev.env
Gateway DEV3 $
$ gw_report integrations long
report is ******
Now i am attempting to automate this process using a shell script:
#!/bin/ksh
sudo su - gvr
. ai_dev3.env
gw_report integrations long
but this is not working. Getting stuck after entering the env.
Stuck at this place (Gateway DEV3 $)
You're not running the same commands in the two examples - gw_report long != gw_report integrations long. Maybe the latter takes much longer (or hangs).
Also, in the original code you run ai_dev.env and in the second you source it. Any variables set when running a script are gone when returning from that script, so I suspect this accounts for the different behavior.
I have asked similar question for Linux RPM (Adding License Agreement in RPM package). Now i have same query for Solaris package. I could not get any helpful link / details if it is possible. But I have found a package which does exactly the same thing but how it has been implemented, its not mentioned.
$pkgadd -d . SUNWsamfsr SUNWsamfsu
Processing package instance from
Sun SAM and Sun SAM-QFS software Solaris 10 (root)(i386) 4.6.5,REV=5.10.2007.03.12
Sun SAMFS - Storage & Archiving Management File System
Copyright (c) 2007 Sun Microsystems, Inc.
All Rights Reserved.
-----------------------------------------------------
In order to install SUNWsamfsr, you must accept the terms of
the Sun License Agreement.
Enter "y" if you do, "n" if you don't, or "v" to view agreement. y
-The administrator commands will be executable by root only (group bin).
If this is the desired value, enter "y". If you want to change
the specified value enter "c". y
...
...
Any ideas how to implement such thing for Solaris package?
I have found a way to solve it.
The self-extracting binary is the way to do it.
Create a shell script which will first dipslay the end user license and take user input whether user agrees or not.
Once user agrees, extract the binary (solaris package file) embed in the shell script and install it.
To embed installer pacakge, first add a marker lets say PKG_DATA:
shell script contents
exit 0
PKG_DATA
Append the package file:
cat pkg_file_name >> your_shell_script
Extract the package and install it:
ARCHIVE=awk '/^__PKG_DATA__/ {print NR + 1; exit 0; }' $0
outname=install.$$
tail -n+$ARCHIVE $0 > $outname
echo "Extracting..."
pkgadd -d $outname
rm -f $outname #we dont need it anymore
exit 0
PKG_DATA
<pkg file data here>
I would implement that using the checkinstall script.
"exit 3" in that script gracefully ends the package installation.
That's not trivial as you need to create a request script and reference it in the checkinstall one.
http://docs.oracle.com/cd/E18752_01/html/817-0406/ch1designpkg-24309.html#ch1designpkg-4