fetching email from outlook O365 by App-wsgetmail for RT using crontab not working - cron

I have configured the modern authentication for O365 using App::wsgetmail module for RT, everything works fine when I run the the wsgetmail --config=config1.json via terminal it can access the email's inbox and create the ticket in RT and mark the email as read but when I am trying to use the crontab to do the same work periodically getting no result.
the corntab works with other cornjobs that I have for other tasks and only it is not working with wsgetmail.
the crontab looks like this:
*/1 * * * * wsgetmail --config=/path_to_config_directory/config1.json
Note:
I am using RT4
The config1.json file is executable
I am using root user for configurations
There is no any error in the logs
Any idea about this issue that I am facing with?

I have finally resolved the issue and posting the answer here for others that may face with same issue.
The crontab and terminal are two different environments, the wsgetmail perl module command is recognizable for terminal but to make it recognizable for corntab we have to add the full path to the module (wsgetmail) in the crontab.
*/1 * * * * /usr/local/bin/wsgetmail --config=/path_to_config_directory/config1.json
or we can create a shell script and call the script in crontab.
in this case test.sh will looks like this:
#!/bin/bash
/usr/local/bin/wsgetmail --config=account01.json
/usr/local/bin/wsgetmail --config=account02.json

Related

How to use cron on a simple script

I want to use cron for execute a script periodically. I want to try a simple script first but it does not work.
This is my script (scritp.sh) which permission are 700:
#!/bin/sh
clear
echo "Hello!"
mkdir Hello
And this is the crontab file when I edit it with the command crontab -e:
SHELL=/bin/sh
* * * * * /home/padro/Documents/script.sh
EDIT:
I have that script on /home/padro/Documents folder. What I do after it is execute the command crontab -e for modify the cron file. In this file I put the shell that I want SHELL=/bin/sh and also the cron schedule expression * * * * * /home/padro/Documents/script.sh. This schedule teorically run the script every minute. Finally I save the file and when a minute passes I can't see the echo of the script on the terminal.
EDIT2:
I have added mkdir hello, because I don't know if the echo of the script is shown on the terminal. But the hello directory is never created.
Any output generated by a program called from cron will by default be emailed to the user owning the crontab (assuming local delivery of mail messages is possible). So I'd suggest that you look in your inbox on the local machine.
To save the output into a file, use a redirection in the crontab, or arrange for the script to write its output to a file.
Jobs started by cron does not run with a terminal, so you should not expect to see your terminal being cleared every minute by running this script through cron.
The Hello folder should have been created in the working directory used by the script (possibly your home directory). To make absolutely sure you know where the script's working directory is, use cd in the script to move to the correct location.
I do not have enough reputation to add comment.
My humble comment would be.
Is the cron file you mentioned via root?
cos chmod 700 a file would be only be executed by owner.
If you are using redhat linux, the user account you use on the first log in is user rights NOT root.
Reference link to a cheat sheet.
su - root
system will prompt root password
crontab -e
* * * * * /home/padro/Documents/script.sh
You can even run a test script, which I did encounter the similar situation as you when I first learnt scripting into your crontab-
* * * * * date > export/home/padro/Documents/testing.txt
If you could, restart the server.
Check if your directory is correct using the command
pwd in linux/unix.
I hope my comment based on my recent learning have helped you.
Edit 1: Remove clear in your script. Thanks...
Edit 2: I believe your Hello folder is created at the core of the root folder try looking for it... or the home directory of the user...

crontab does not execute python script

I am facing an issue of crontab does not run the python script in Raspbian GNU/Linux 9.4 (stretch) installed on a Raspberry Pi3. I have done lots of research on this topic e.g. by following the troubleshooting guide in https://askubuntu.com/questions/23009/why-crontab-scripts-are-not-working/24527#24527 , but none of them solved my issue.
The python script that I want to run is located in
/home/pi/Documents/Fork_BookManager.py
I have made sure that anyone can execute, read and change content to the above file.
I can run this file through terminal by writing
usr/bin/python3 /home/pi/Documents/Fork_BookManager.py
I know the file is running, because the Fork_BookManager.py is using selenium to open a web browser, and I see this web browser being opened. There is no error observed when running the Fork_BookManager.py file from terminal.
In terminal executed
crontab -e
Using nano as editor, I first verified that crontab acutally worked by
* * * * * env > /home/pi/Documents/env.output
After a minute there is a env.output file in Documents folder with below parameters.
LANGUAGE=da_DK.UTF-8
HOME=/home/pi
LOGNAME=pi
PATH=/usr/bin:/bin
LANG=da_DK.UTF-8
SHELL=/bin/sh
LC_ALL=da_DK.UTF-8
PWD=/home/pi
I noticed that the path from crontab is different from the path when env is called from terminal as I will have the below path if I call env from terminal
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
So I know that crontab -e was working since I otherwise would not have got the env.output file created in Documents folder. I proceed by calling crontab -e from terminal and copied the path from env into the crontab like below
PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
* * * * * /usr/bin/python3 /home/pi/Documents/Fork_BookManager.py
Saved the script and waited. Nothing happend.
To summerize I have:
Made sure that the Fork_BookManager.py is executable
Verified that crontab is working
Updated path from env into the crontab script
which are three largest cause of experiencing difficulties in making crontab to work according to this guide
https://askubuntu.com/questions/23009/why-crontab-scripts-are-not-working/24527#24527
Still it is not working. What have I missed? Is there a better practice to achieve what I want, namely to execute the python script once a minute without doing it directly from the python script itself such as a while loop with a time.sleep(60)
ADDITIONAL INFORMATION
I even tried to expand the path in crontab script by
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/bin:/home/pi/Documents
in an attempt to specify in which folder the python3 and Fork_BookManager.py is located. Still no luck.

How Do I execute a .sh script using cpanel cron job

Im very new to command line so please forgive my ignorance. I can succesfully execute my script using putty by navigating to the relevant direcotry and typing
bash app_auth.sh
I'm now trying to set this scipt to run using cPanel cron job. I have tried the following but it doesnt work:
* * * * * /public_html/app/cron_jobs/app_auth.sh
Any help would be appreciated..
Though this thread is old but I found it unanswered hence replying.
Make sure that you have assigned execute permissions to your app_auth.sh file. Also, try setting the following cron:
* * * * * /public_html/app/cron_jobs/app_auth.sh > /home/YOUR_USER/cron.log 2>&1
Just for the record, I came across the same problem.
I found this webpage, which led me to do this:
/bin/sh /public_html/app/cron_jobs/app_auth.sh
And it worked fine!

crontab not working fine?

i have this crontab,
* * * * * php /etc/raddb/overloaded.php
but it is not running fine, meaning it doesnt run every minute, but when i manually enter this into the terminal (php /etc/raddb/overloaded.php), the script works
thank you guys
PS: im using centos 32 bit. also im using the "crontab -e" to insert and save crontab, but it looks like that crontab is not running? i typed "crontab -e" and yet (* * * * * php /etc/raddb/overloaded.php) appears. where is the issue here? thanks
Crontab syntax is right. Please check if your cron daemon is running and you can check log, maybe it conatins some usefull info.
I think the most possible problem is that cron has its own environment settings. Try to run php with its full path, e.g.
/sbin/php
or w\e path you have

Perl script executed by Cron failed

I maintained a database (MySQL), I would like back up some data to the database using a perl script. To save my trouble, I would like cron to do it for me, I inserted the following using crontab
*/5 * * * * blctrl /home/blctrl/code/perl/tt01.pl
However, cron never does its job, any suggestions to get it done? The Linux installed is Centos 5?
*/5 * * * * blctrl /home/blctrl/code/perl/tt01.pl
That looks like the syntax for /etc/crontab, the system-wide crontab file. The first 5 words indicate when to run the command, the 6th is the account under which to run it, and the rest of the line is the command to execute.
(The clue was that the command is under /home/blctrl, which would be the home directory for the account blctrl.)
The syntax for your own crontab, the one you feed to the crontab command, is different. You don't specify an account name, because it only runs under your own account.
Try this:
*/5 * * * * /home/blctrl/code/perl/tt01.pl
EDIT: Incidentally, the first thing I would have tried when encountering a problem like this would be to replace the command with something simple, perhaps touch /tmp/FOO. That would have told you whether the problem was with your Perl script or with your crontab.

Resources