Linux: Crontab Job without Interfering with Sys Admin's Jobs? - linux

I need to create a new crontab job in a Redhat Linux environment. I have sudo access to that but I don't think I can do everything on that system--some higher level sys admins, for example, disable any firewall changes I make.
So here is my crontab command:
crontab e
and that brings up a screen like:
33 2 * * * /usr/bin/cu-firewall update > /dev/null 2>&1
30 1 * * * /root/update_atbi_website > /dev/null
0 4 * * * /home/prov356/scripts/opnforumbackup
I want to not send email and I have done it successfully in my local VM:
MAILTO=""
# execute 15 minute
*/15 * * * * perl /db_xenia/pl/get_usgs.pl
Question: If I were to append the above to the existing crontab info will it prevent sending of emails to the sys admin too? I don't want to get into trouble! Perhaps, I could append /dev/null after my Perl commands?
Thanks.

Never mind: Per #Basile's comment, I didn't need to be sudo. So I logged in as non-sudo and ran crontab -e; this time there were no sys admin entries. So I simply entered my own configs, saved, and the cronjob seems to be running fine.
Thanks.

Related

CRON job outputting blank lines

I tried to create a CRON job that runs every minute. As a root user, I ran crontab -e, and in the cronjob, I put in my command * * * * * /usr/bin/php {redacted}/index.php > {redacted}/output.txt
the {redacted} file path has permissions added: chmod ogu+rwx -R so everyone should be able to access it. I even created a new user with no sudo or root privileges, and running /usr/bin/php {redacted}/index.php > {redacted}/output.txt obviously writes the output of {redacted}/index.php to {redacted}/output.txt. However, my cron job ends up overwriting and turning the .txt file to just blank, nothing. I have no idea what is going on since I already made sure there were no permission errors, and cron jobs don't seem to have a visible log or output?
I would love to have any ideas about this. I even tried to add the cron job * * * * * root /usr/bin/php {redacted}/index.php > {redacted}/output.txt, all to the same output.
One more thing... I have tried to set the {redacted} location to /var/www/html, /var/www/{a user with sudo perms}, and {/usr/local/bin} all with the same result.
Update:
I tried something as simple as * * * * * php -v > {redacted}/output.txt and * * * * * /usr/bin/php -v > {redacted}/output.txt still with the same result, so it seems like the error is not with requiring root permissions to run my php program

Crontab - simple echo not running

I've got such situation:
I want to schedule a job with crontab on a linux server. I'm not super-user, so I'm editing (with crontab -l, editor vim) only my crontab file. For testing, I put there:
* * * * * echo asdf
And the job is not running. Is the restart of the server needed? Or maybe some administrator move?
May be it is, cron jobs will run in their own shell. So you can't expect to see asdf on your console.
What you should try is
* * * * * echo asdf > somefile_in_your_home_directory_with_complete_path.log
Next check the file by doing a tail:
tail -f somefile_in_your_home_directory_with_complete_path.log
And if it's not, check if the cron daemon itself is running or is down:
# pgrep crond
OR
# service crond status
If you want to echo something on your shell you could use wall:
* * * * * wall <<< "Hello from cron"
* * * * * echo "Hello from cron" | wall
These two lines basically do the same but the first one might not work on older shell, just choose your favorite.
Anyway, be aware that wall will send your message to every user currently connected.
For me * * * * * /bin/echo text > file is not working...I don't know why, previleges and everything is set.
(This command is running normaly when I execute it as the particular
root user, just to clarify this.)
This can be solved by injecting the path PATH=$PATH:/bin in my example.
Instead * * * * * echo text > file is working fine, probably path issue.
Hope I helped

How to reboot via cron on scheduled basis. Ubuntu 14.04

I have a very simple script that works from the command line.
#!/bin/bash
reboot
When I put a call to execute the script into root users crontab -e using the following format it does not run. It does run the first two commands, just that last one is giving me grief. I have no MTA installed as I do not need it.
*/10 * * * * service jwtpay restart
0 3 * * * bash /root/backup/mongo.backup.s3.sh kickass /root/backup >/dev/null 2>&1
0 */3 * * * bash /root/reboot.sh >/dev/null 2>&1
What am I missing?
Maybe the script is not executable... Since you use root's crontab why call the binary via a script and not the binary itself? Use the full path to the binary. It may vary on your system. Find out where it is with which reboot.
0 */3 * * * /sbin/reboot
Don't forget to restart the cron daemon, after changeing the crontab.

crontab being saved in tmp/ in debian

I'm trying to make a crontab with crontab -e, but it saves it in tmp/crontab.FTt6nI/crontab
the crons don't work so I guess that's the problem. But I don't understand why.
type:
crontab -l
to show list of crontab, your newly added crontab should be on the list. you could set the crontab to email the output to you by > youremail#aaa.com, in this way you can assure the cronjob is already run.
example:
* * * * * /usr/bin/php /home/username/public_html/cron.php > aaa#aaa.com
make sure the crond is running:
/etc/init.d/crond status
if it down, start it (centos/rhel):
/etc/init.d/crond start
debian/ubuntu:
/etc/init.d/cron start
hope that help.

Using Cron to Reboot

I'm using a Raspberry Pi for a status display, but for whatever reason it gets incredabbly sluggish after a day or so of running so I wanted to reboot it every day so I setup a cron job to do that every morning at 8:50. But, it doesn't seem to be working. Is there anything special about using cron to do a reboot?
This is my crontab for the root user:
# m h dom mon dow command
50 8 * * * shutdown now -r >> /var/log/cron.log
0,30 * * * * date >> /var/log/cron.log
The second line works just fine, but I can't seem to get the restart command to work. It doesn't even output anything to the log.
Try using the fully specified path to shutdown. date may be in the PATH in roots cron environment, /sbin may not be looked up.
You need to edit the root user crontab
sudo crontab -e
then..
50 8 * * * reboot
Save and exit.

Resources