I want to use script chmod automatically every minute this is my script? - linux

I want to use script chmod automatically every minute this is my script
# vim /home/crontab/chmod.sh#!/bin/shchmod +x /home
And this is my crontab
# crontab -e */5 * * * * /home/crontab/chmod.sh
What's wrong on my script and my crontab ?

Cron expression for every minute:-
*/1 * * * * <ur command>
And to execute your script first do chmod on your script.
chmod +x /home/crontab/chmod.sh
And don't forget to add a blank new line in the end of your crontab as well as Shell script.

Related

Shell Script not executing, added to crontab

Here is my shell script, myscript.sh located in ~/bin
cd ../environment
. env/bin/activate
python3 office.py
The script office.py updates the database. I've tested and works with no issue. I used this command ./myscript.sh
Here is cronjob */5 * * * * cd ~/bin/myscript.sh added to crontab -e
When i check database, no changes. The cronjob isn't running? How do i solve?
You are not running the script but just trying to change directories, which will fail as myscript.sh is not a directory. You need to first cd ~/bin as you are using relative paths in your script and then run the script. Use this line:
*/5 * * * * cd ~/bin && ./myscript.sh
Also you may wanna check the syslog to check for cronjobs.
grep CRON /var/log/syslog
Have a look at this thread for more information on logging cronjobs.

Crontab with delete before sync

I have a question, i build on this moment a loadbalancer server with 2 servers. Now i have the sync with crontab.
But if i delete a file or directory on server 1 than stay the file on server 2. and if i delete a file or directory on server 2 than stay the file on server 1.
This my crontab from server 1
SHELL=/bin/bash
HOME=/
*/1 * * * * date >> /var/log/rsync_log
*/1 * * * * rsync -avrhe --delete-before 'ssh -p SSHPORTNUMBER' USERNAME#IPTOSERVER2:/home/ploi/ /home/ploi/ >> /var/log/rsync_log
This my crontab from Server 2
SHELL=/bin/bash
HOME=/
*/1 * * * * date >> /var/log/rsync_log
*/1 * * * * rsync -avrhe --delete-before 'ssh -p SSHPORTNUMBER' /home/ploi/ USERNAME#IPSERVER1:/home/ploi/ >> /var/log/rsync_log
Can anyone help me to fix this problem?
Thanks.
Willem
you can add a shell script , which write delete command, and use crontab to exec it;
when you want to delete a file, you just write command to this sh file, sh file will sync to other server, then use crontab to exec this sh file to delete the real file.

Why is my crontab -e not running my python script?

I want to run hello.py file which contains print("Hello World") using crontab.
For that, my hello.py has this code:
#! /usr/bin/python3
print('Hello, world!')
And, in the same folder, I have used crontab -e command to open crontab and in order to execute this file every minute, I have written:
1 * * * * ./hello.py
I have also set permissions for the file to be executable using chmod a+x hello.py.
When I run
/usr/bin/python3 hello.py
It runs perfectly. Also, when I use only ./hello.py, the file runs.
Why is it still not executed using crontab?
Nailed it!
Instead of using 1 * * * * ./hello.py in crontab to set the cron running per minute , I rewrote the statement to 1 * * * * /usr/bin/python3 hello.py .
This solved the problem!

Cron job does not run in RHEL

I'm running RHEL and I'm trying to set up a cron job to run a shell script every 5 minutes.
Following the directions here: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Automating_System_Tasks.html#s2-configuring-cron-jobs
I have service crond start and chkconfig crond on. Then I edited /etc/crontab and added:
*/5 * * * * my-user /path/to/shell.sh
I did a chmod +x shell.sh. And I made sure to add a new line character at the end.
I'm expecting it to run every 5 minutes but it never executes.
What am I doing wrong?
Simply try to add the cronjob entry and check the script is working fine or not by taking the viewable output in the script.
echo "test time - $(date)" > script.sh
chmod +x script.sh
crontab -e
Then enter the cronjob as below,
*/5 * * * * sh /path/to/script.sh > /path/to/log.file
Check if the log is writing correctly. If its fine, better cross check the script that you are trying to execute via cron. Otherwise it will be a cron issue.

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.

Resources