CRON job not setting up on linux - module

I have setup the corn command using crontab -e command.
MAILTO=""
* * * * * /usr/bin/php7.2 /var/www/vhosts/hostname/httpdocs/bin/magento cron:run --group="test"
I have created module to run CRON job automatically. But it is not working automatically.
Instead when I hit command php bin/magento cron:run it works.
I am surprised cron task is performing manually but not automatically.

My bad. It is working fine now.
The actual issue was with the user setting up the CRON job. I was setting the CRON job with root user. Later I set up the same CRON using developer user having ftp access and it worked perfectly.

Related

Using rsync preserving all the attributes and as foreground job

I have a server which is always online, I want during night hours, to run a job on the server that simply copies from /folderA -> /folderB.
I would not like to keep my screen on while my rsync is performing the job.
Is there any way of using this command:
rsync -avhW --no-compress --progress folderA/. folderB/
while I turn off my SSH station (laptop)?
Thanks
You are looking to setup a cron job. Cron jobs are tasks that run automatically on a schedule. To setup your rsync job:
Login to your server via SSH
Run crontab -e. This will open a file in the server's default text editor. Typically, this file will have some comments with details on how to add a job
To the last line of the file, add 30 11 * * * rsync -avhW --no-compress --progress folderA/. folderB/. This will run the job at 11:30PM every day. For changing the scheduled time, see the link above.
Save and exit
You can now logout from the server and the job will run every day at the scheduled time. Since the job is scheduled on the server, your workstation can be off and you do not need to logged into the server. The task will keep running on schedule until you remove the line from the crontab file.

How to setup a custom cron job in opencart?

Can anyone tell me how can I setup a custom cron job in opencart?
I have Url in below format and when I am manually hit this url it works perfectly now I want to make it dynamic on cron schedule basis.
I have setup cron job in https://cron-job.org/en/ using below URL and it works fine but I'm not sure whether it is the right way or not?
> http://www.yourstore.com/admin/index_for_cron.php?route=module/modulename/function
Thanks in advance..!
There you'll find instruction:
http://docs.opencart.com/en-gb/extension/cron/
If you able to setup cron tasks on your web-server, you are always can use curl:
curl -s "http://www.yourstore.com/admin/index_for_cron.php?route=module/modulename/function" >/dev/null
I'm also managed to run my custom modules for OpenCart3 with command like this:
cd /path/to/your/site && QUERY_STRING="route=module/modulename/function" php -r 'parse_str($_SERVER["QUERY_STRING"],$_GET);include "index.php";'
(But in this case you need to consider file permissions and run task under appropriate user.)

Running a crontab job from locally stored script

Having trouble running a crontab psql backup job from a locally stored script. I added the job via crontab -e and when I used crontab -l, it shows up in the list of jobs. The script that it is supposed to run works fine, checked that, runs as it should and dumps the output on the designated s3 bucket when using ./backup.sh
This is what I set the job as:
59 23 * * 7 /Users/myusername/backup.sh
The job should run at 11:59PM every Sunday, but it doesn't. I can't figure out what the issue is (do I need to leave line breaks/spaces in between each job, or just after the very lost job in my crontab list?
Any help would be very much appreciated. Thanks.
Depending on your distribution, you might want to check logs for Cron service.
Non-exhaustive list of possible problem reasons:
Cron service is not running at all and hence is not starting any of the tasks;
Usually Cron passes your script a very limited set of environment variables, so your script might fail because of some missing environment. That will probably be reflected in cron daemon logs
What can you do
Cron service: if your distro uses systemd then try running systemctl status cron (or systemctl status crond?) to check if it is running.
Your script is started but fails: here are several things to try.
Try checking cron service logs, maybe with something like journalctl --unit cron or journalctl -f before the script should be started;
Check if there is a dead.letter file in your home directory containing output of the failed script. When Cron starts your script and the script outputs something (which is considered a problem), that output is mailed to you. If mailing is not properly configured then it usually goes to that file.
Put something like this in the beginning of your script:
(
date
id -a
set
echo
) >> /tmp/myscript.log
Then wait until cron runs your script and check if the file /tmp/myscript.log was created. Then try to run your script manually, replicating all the environment created by cron which you now know. I.e. unset all but the variables Cron leaves, and make sure id is correct.

Jenkins SSH remote process is getting killed as soon as the Jenkins SSH plugin returns back

Jenkins version: 1.574
I created a simple job which performs the following:
Using "Execute shell script on remote host using SSH" as one of the BUILD steps, I'm just calling a shell script. This shell script performs stop and start operations on Tomcat to restart an application on the target machine.
I have a valid username, password, port defined for the target SSH server in Jenkins Global settings.
I saw this behavior that when I run a Jenkins job and call the restart script (which gets the application name as parameter $1), it works fine, but as soon as "Execute shell script on remote host using SSH" step completes, I see the new process dies on the remote/target application server.
If I run the script from the target/remote server itself, everything works fine and the new process/PID remains live forever, but running the same script from Jenkins, though I don't see any errors and everything works as expected, the new process dies as soon as the above mentioned SSH step is complete and control comes back to the next BUILD step in Jenkins job OR the Jenkins job is complete.
I saw a few posts/blogs and tried setting: BUILD_ID=dontKillMe in the Jenkins job (in various places i.e. Prepare Environment variables and also using Inject Environment variables...). When the job's particular build# is complete, I can see Environment Variables for that build# does say BUILD_ID=dontKillMe as its value (instead of the default Timestamp tag value).
I tried putting nohup before calling the restart script, i.e.,
nohup restart_tomcat.sh "${app}"
I also tried:
BUILD_ID=dontKillMe nohup restart_tomcat.sh "${app}"
This doesn't give any error and creates a nohup.out file on the remote server (but I'm not worried about it as the restart_tomcat.sh script itself creates its own LOG file which I'm "cat"ing after the restart_tomcat.sh script is complete. cat'ing on the log file is performed using another "Execute shell script on remote host using SSH" build step, and it successfully shows the log file created by the restart script).
I don't know what I'm missing at this point, but as soon as the restart_tomcat.sh step is complete, the new PID/process on the remote/target server dies.
How can I fix this?
I've been through this myself.
On my first iteration, before I knew about Jenkins ProcessTreeKiller, I ended up just daemonizing Tomcat. The Apache Tomcat documentation includes a section on running as a daemon.
You can also try disabling the ProcessTreeKiller for your whole Jenkins instance, if it's relatively small (read the first link for information).
The BUILD_ID=dontKillMe should be passed to the shell, and therefore it should be in your command line, not in Jenkins global configuration or job parameters.
BUILD_ID=dontKillMe restart_tomcat.sh "${app}" should have worked without problems.
You can also try nohup restart_tomcat.sh "${app}" & with the & at the end.
My solution (it worked after trying everything else) in Ubuntu 14.04 (Trusty Tahr) (Amazon AWS - Amazon EC2), Jenkins 1.601:
Exec command: (setsid COMMAND < /dev/null > /dev/null 2>&1 &);
Exec in PTY: DISABLED
// Example COMMAND=socat TCP4-LISTEN:1337,fork TCP4:127.0.0.1:1338
I created this Transfer as my last one.
#!/bin/ksh
export BUILD_ID=dontKillMe
I added the above line to the start of my script and the issue was resolved.

Writing a crontab job that references a properties file

I am running Ubuntu Server 12.04. I am trying to set up a cron job to run every week. If I were to write this command in the command prompt, it would look like this:
name#computer:~/./runReport.sh weekly_ecc_name.properties
It works when run at command like the above
Now this is what I have for the cron job:
* * * * * /runReport.sh weekly_ecc_name.properties > errors.txt 2>&1
I'm having it run every minute until I get it working.
The error that it spits out is Error: Could not find or load main class blarg (which refers to the file that reads the properties file).
I am not quite sure how to write this so that it works. Thanks for your help.