My crontab file has following:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * * /bin/bash /root/bin/run1.sh
run1.sh has
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
export DISPLAY=:0.0
cd /root/madhu_test/bpstest/
touch bhasina.txt
./bpsh-linux-x86-3.1 appTest_saurav.tcl apptest.ini.96.70.NSSTuned NSS-Tuned
./bpsh-linux-x86-3.1 appTest_saurav.tcl apptest.ini.96.70.S2C CriMajMinS2C
But crontab is unable to run the binary file bpsh-linux-x86-3.1. However touch works.
Related
I'm trying to set a task to run a script from such a sh-file (run_a.sh)
#!/bin/bash
cd /home/userdir
source venvProject/bin/activate
cd /home/userdir/scrapy_project
PATH=$PATH:/usr/local/bin
export PATH
scrapy crawl my_spider
My crontab string looks like this:
*/5 * * * * sh /home/userdir/run_a.sh
but it don't works, whats wrong?
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.
Hoping someone can help with a crontab issue I am having on the pi.
I have a program, rf24_receiver.py, that resides in the /home/pi directory. When run from terminal, it requires sudo to run. So with this command on terminal,
sudo python3 rf24_receiver.py, the program executes perfectly.
However, I need to run it on a schedule, so I tried the following without success.
crontab -e
*/30 * * * * sudo python3 /home/pi/rf24_receiver.py >> /home/pi/rf24_receiver.py.log 2>&1
Then I tried this
*/30 * * * * python3 /home/pi/rf24_receiver.py >> /home/pi/rf24_receiver.py.log 2>&1
Then I tried this
sudo crontab -e
*/30 * * * * sudo python3 /home/pi/rf24_receiver.py >> /home/pi/rf24_receiver.py.log 2>&1
Then I tried this
*/30 * * * * python3 /home/pi/rf24_receiver.py >> /home/pi/rf24_receiver.py.log 2>&1
No success with any of the above. I hope this is the right place to post this.
Any help would be appreciated.
Thank you
Sorry to bother the forum with this question. I am not sure why I got this command to work under sudo crontab -e:
*/29 */1 * * * sudo python3 /home/pi/rf24_receiverR3.py >> /home/pi/rf24_receiverR3.py.log 2>&1
I did a reboot and it seemed to work after that.
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.
This is my perl script, it's just a test.
#!/usr/local/bin/perl
open (MYFILE, '>>data.txt');
print MYFILE "Worked!\n";
close (MYFILE);
I saved it as test.pl in cgi-bin/
When I run a shell command,
root#srv ./test.pl
it works fine and it adds "Worked!" in the data.txt file successfully.
But when I add this in cronjob to run every minute it doesn't work
code:
*/1 * * * * root cd /home/testing/public_html/cgi-bin;./test.pl
I've also tried
*/1 * * * * cd /home/testing/public_html/cgi-bin;./test.pl
I'm thinking it's my environment for cron that's not setup correctly, but I don't know how to fix it.
I've used this in crontab to execute the env
*/1 * * * * env > /home/tmp2/env.cron
And Here is the result:
SHELL=/bin/sh
USER=root
PATH=/usr/local/jdk/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin
PWD=/root
SHLVL=1
HOME=/root
LOGNAME=root
_=/bin/env
And then I exported the env of the shell i'm using to another file env.shell
results:
HOSTNAME=srv.testing.com
SELINUX_ROLE_REQUESTED=
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=xxx.xx.xxx.xx 58048 22
SELINUX_USE_CURRENT_RANGE=
QTDIR=/usr/lib64/qt-3.3
QTINC=/usr/lib64/qt-3.3/include
SSH_TTY=/dev/pts/0
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=0$
MAIL=/var/spool/mail/root
PATH=/usr/local/jdk/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin
PWD=/home/tmp2
JAVA_HOME=/usr/local/jdk
EDITOR=pico
LANG=en_US.UTF-8
SELINUX_LEVEL_REQUESTED=
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LS_OPTIONS=--color=tty -F -a -b -T 0
LOGNAME=root
VISUAL=pico
QTLIB=/usr/lib64/qt-3.3/lib
CVS_RSH=ssh
CLASSPATH=.:/usr/local/jdk/lib/classes.zip
SSH_CONNECTION=xxx.xx.xxx.xx 58048 xx.xx.xx.xx 22
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env
OLDPWD=/home/testing/public_html/cgi-bin
I copied the shell path
PATH=/usr/local/jdk/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin
And added it to /etc/crontab and I restart cron but it still didn't work. So, I changed it back to normal, and then I added it to crontab using crontab -e and it still didn't help.
I'm not sure what is going on,
Thank you for your time
I finally solved it!
I changed the path of crontab -e
PATH=/usr/local/jdk/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin
That's the same path in my shell you can get it if you do this
root # env > env.shell
root # nano env.shell
then copy the path from there, and paste it in crontab using crontab -e
Then, the last step was to add it to crontab -e, but after I added the path I had the cronjob in /etc/cron.d/sysstat so that's why it wasn't working.
Now it works and the main problem was the PATH.
Thank you for your time everyone.
Try
* * * * * root cd "/home/testing/public_html/cgi-bin"; ./test.pl