Cron Error :(cd) ERROR (getpwnam() failed - user unknown) - linux

I have a simple bash script and it works fine when I execute it directly (bash testfile.sh). But when I use it in crontab, it is not working..
*/10 * * * * cd /var/trafficviewer/script; ./testfile.sh
I made the chmod +x testfile.sh as well.In error log, I could found below error..
Jul 12 16:45:01 XX crond[1439]: (cd) ERROR (getpwnam() failed - user unknown)
Can someone help me on this error?
Note: I dont have root access for this server. I installed these crons by using sudo commands.

Related

Crontab not sending Sendgrid emails from Python script on AWS Linux 2

I have an AWS Amazon Linux 2 box. I am using a python script (Python 3.7) to send an email using Sendgrid as the SMTP service. I can send the email using $ python3 send_email.py but, when I use crontab ($ crontab -e then * * * * * python3 ~/apps/send_email.py), the error in the log file /var/log/cron is (CRON) EXEC FAILED (/usr/sbin/sendmail): No such file or directory. The crontab is working as expected (I've tested other cron commands and they work fine), but the email part is what's not working.
Here's what I've tried to fix it:
Run the command as a root crontab (ie $ sudo crontab -e)
Run the the crontab as a user crontab (ie $crontab -e)), but with sudo python3 ... in the crontab command.
Add the path directory at the top of the crontab file in case those directories couldn't be resolved
Installed Postfix to install something in the /usr/bin/sendmail directory but, since I don't need it to run the Sendgrid-powered email using $ python3 send_email.py, I'm not sure why I would need it through cron. I could be totally wrong on this, though. With Postfix installed, it resolves the (CRON) EXEC FAILED (/usr/sbin/sendmail): No such file or directory error in the cron log - the log entry in that case is (ec2-user) CMD (python3 ~/apps/send_email.py) - but I don't receive an email. Probably because Postfix isn't configured for the SMTP I'm using (Sendgrid).
(EDIT) I have configured Sendgrid to work with Postfix via the Sendgrid docs but it still won't send me an email although it looks like nothing is erroring out in the Postfix logs...
Jun 1 20:27:02 ip-[my-ip] postfix/pickup[25506]: 101769641F3: uid=1000 from=<ec2-user>
Jun 1 20:27:02 ip-[my-ip] postfix/cleanup[25508]: 101769641F3: message-id=<20210601202702.101769641F3#ip-[my-ip].us-east-2.compute.internal>
Jun 1 20:27:02 ip-[my-ip] postfix/qmgr[25507]: 101769641F3: from=<ec2-user#ip-[my-ip].us-east-2.compute.internal>, size=1165, nrcpt=1 (queue active)
Jun 1 20:27:02 ip-[my-ip] postfix/local[25510]: 101769641F3: to=<ec2-user#ip-[my-ip].us-east-2.compute.internal>, orig_to=<ec2-user>, relay=local, delay=0.01, delays=0/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Jun 1 20:27:02 ip-[my-ip] postfix/qmgr[25507]: 101769641F3: removed
My thought is that there is something in the cron call of the Sendgrid python lib (installed with sudo pip install sendgrid) that is failing out that doesn't happen when python calls it directly using the python3 interpreter from the CLI. I don't know why those would be different.
I was able to finally resolve this after much troubleshooting. Here's what worked.
I kept the original setup the same: Sendgrid for SMTP using their python lib (no Postfix or smtplib), using user crontab (using $ crontab -e not $ sudo crontab -e), and using Python 3.7.
Apparently the word 'email' in the python script name can cause interpreter issues so I renamed the file to remove the word 'email'. For example, send_noti.py instead of send_email.py
I used absolute paths for every call to a file in the python script. I was reading, writing, and executing files in the user directory in my python script as well as sending an email. Those R,W,X commands started erroring out in cron but not when called from outside of cron for some reason, even after renaming the file. Using absolute paths for all references to files fixed that.
I also used the absolute path for the python file in the crontab file. For example, * * * * * python3 /home/ec2-user/apps/send_noti.py instead of * * * * * python3 ~/apps/send_noti.py
I removed the unnecessary items in the crontab file I had put in before such as redefining the PATH directory.
I hope this helps someone because this took me about 3 weeks to troubleshoot and figure out.

Jenkins console shows permission denied error when I run the test.sh file

I have created one .sh which contains java command required to run the tesng.XML file when I run this test.sh file on Jenkins it shows me permission denied error.
Jenkins console output:
Building in workspace /home/dev2/eclipse-workspace/weeklytask
[weeklytask] $ /bin/sh -xe /tmp/jenkins7439378074963422991.sh
+ ./test.sh
[TestNG] Running:
/home/dev2/eclipse-workspace/weeklytask/enquiryreminder.xml
Starting ChromeDriver 2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7) on port 8120
Only local connections are allowed.
FOLLOW UP REMINDER CRON WEEKLY CHECK TESTCASE FAILED
PLEASE CHECK THE TIME INTERVAL SETTING
SET THE TIME INTERVAL TO 600
FOLLOW UP REMINDER CRON WEEKLY CHECK TESTCASE FAILED
PLEASE CHECK THE TIME INTERVAL SETTING
SET THE TIME INTERVAL TO 600
[[Utils]] Error while writing to /home/dev2/eclipse-workspace/weeklytask/test-output/Suite/Test.html: /home/dev2/eclipse-workspace/weeklytask/test-output/Suite/Test.html (**Permission denied**)
[[Utils]] Error while writing to /home/dev2/eclipse-workspace/weeklytask/test-output/Suite/Test.xml: /home/dev2/eclipse-workspace/weeklytask/test-output/Suite/Test.xml (Permission denied)
===============================================
Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
[[Utils]] Error while writing to test-output/junitreports/TEST-verify.enquiryremindertest.xml: test-output/junitreports/TEST-verify.enquiryremindertest.xml (Permission denied)
Jenkins use the user jenkins. If you have created your file with other user, there might be permission issue on the file. To resolve change the permission on the files and allow other users to execute the script. You can use
chmod +x test.sh
The directory eclipse-workspace belongs to dev2 user and here jenkins user is trying to write data in it. Give jenkins write permission on this folder. try
sudo chmod -R a+rw /home/dev2/eclipse-workspace
For more details about permission you can view This tutorial

Redmine Cron Job Issue

I must set a Cron Job on Redmine to automatically manage IMAP fetching. I try to supply as many infos as I can about my environment:
Redmine version 3.2.0.stable
Ruby version 2.1.5-p273 (2014-11-13) [x86_64-linux-gnu]
Rails version 4.2.5
Environment production
Database adapter Mysql2
I have installed luismaia/redmine_email_fetcher as a plugin, and I have configured it for gmail IMAP. Up to this point I had no error messages and, by trying a test tool on Redmine, I get a success message.
I sum up the plugin configuration on Redmine as it follows:
Configuration type: IMAP
Is configuration active? true
Host : imap.gmail.com
Port: 993
SSL? yes
Email username: mailAddress
Password: mailAccountPwd
Folder Name: Inbox
Method for unknown users: accept
Now, I must run a Cron Job. At this link:
https://github.com/luismaia/redmine_email_fetcher
I have found the following:
*/5 * * * * www-data /usr/bin/rake -f /opt/redmine/Rakefile --silent redmine:plugins:email_fetcher:fetch_all_emails RAILS_ENV=production 2>&- 1>&
that I personalize as it follows:
*/5 * * * * www-data /usr/bin/rake -f /opt/redmine/Rakefile --silent redmine:plugins:email_fetcher:fetch_all_emails RAILS_ENV=production host=imap.gmail.com username=mailAddress password= mailAccountPwd port=993 --trace
Coming to the point: the line above doesn't work; and I've no idea why.
I can add that:
in /usr/bin I see rake2.1
opt directory (/var/opt) is empty.
I do hope I have explained my issue in a decent way.
Thank you in advance, really.
ps:
I tried also:
*/5 * * * * www-data /usr/bin/rake2.1 -f /var/www/redmine/Rakefile redmine:plugins:email_fetcher:fetch_all_emails RAILS_ENV=production 2>&- 1>&-
but nothing happens.
Test the which command:
which rake
for me it's in /usr/local/bin and not in /usr/bin
Next try to chdir in your redmine folder before launch the command in the crontab:
*/5 * * * * cd /var/www/redmine/ && sudo /usr/local/bin/rake redmine:plugins:email_fetcher:fetch_all_emails RAILS_ENV=production 2>&- 1>&-
Hope this can help you.
Cheers,
Luc

Setting up a crontab on debian/LINUX server

I am trying to set up a crontab for a drupal 7 site. I installed elysia cron to schedule it and if I force it to run it runs fine. However I am having difficulty setting it up to call the cron.php file .
This is what I have on my crontab -e
*/5 * * * * /usr/bin/php "/var/www/test.ccc.com/cron.php"
And this is the error that I have been getting on my var/mail
PHP Warning: include_once(/home/neela/includes/bootstrap.inc): failed to open stream: No such file or directory in /var/www/test.ccc.com/cron.php on line 13
PHP Warning: include_once(): Failed opening '/home/neela/includes/bootstrap.inc' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/test.ccc.com/cron.php on line 13
PHP Fatal error: Call to undefined function drupal_bootstrap() in /var/www/test.ccc.com/cron.php on line 14
Also my test.ccc.com server is not live yet.
Any ideas?

Cronjob doesn't execute (Cygwin)

I'm using Cygwin to synchronize folders between a Windows-Machine and an Apache server. It works fine if I execute the commands, but I can't get Cronjob to work properly.
I tried to create a simple mkdir command as a cronjob and when I save the crontab, it successfully installs it.
My Cronjob is:
*/1 * * * * mkdir newfolder
I wait for the new folder to pup up, but nothing happens.
In the cron.log it says:
Cron 7072 fork: child -1 - CREATEPROCESSW failed for c:cygwin/usr/sbin/cron.exe, errno 30
Can anybody help?
I solved the problem: (drumroll)
I reconfigurated it... often!
I kept trying "cron-config" time after time and now it works. I'm still not any smarter what I configurated wrong/right.
I'm sorry for the vague help if anybody with the same problem stumbles upon this.

Resources