Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Ok, so I'm trying to set cron to run a bash script at a certain time. My bash script is essentially this
#!/bin/bash
espeak -g 3 "this is my text"
So from there, I went to the crontabs, and added in
*/1 * * * * /path/to/my/script.sh
to see if it would run, but it didn't do anything. I changed the script to
#!/bin/bash
echo "this is my script"
to see if that would do anything, but no avail. Any help? Thanks.
Try to run the script manually and see if it echos out: bash /path/to/my/script.sh
Does the file have the correct permissions?
Try Outputting errors to a log file: */1 * * * * /path/to/my/script.sh > /path/to/my/error.log 2>&1
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I want to set cron in ubuntu server,but when I run command crontab -e, I see this status or error. no crontab for root - using an empty one 888
How can I fix this.
I know what you mean, it shows a line "888" when you run command crontab -e.
That's because you chose /bin/ed as your editor, but you are not familiar with it.
Just vi ~/.selected_editor , you'll see it and change the value to /usr/bin/vi .
Then run command crontab -e again, it will be what you want.
Your crontab editor has been switched to ed. To exit ed, press Q and subsequently Enter. This will quit the ed editor.
If you would like to change your crontab editor back to nano, use:
sudo select-editor
This also might be helpful:
EDITOR=nano crontab -e
This just means there isn't a crontab so it's generating one.
Once it opens, you should be able to save it then the warning won't appear again.
If you're using nano as a text editor (some defaults), you can press Ctrl+X then Y to confirm and it should save/update the crontab.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I've already posted this question here:
https://superuser.com/questions/1067609/how-to-run-a-bash-script-via-absolute-path
But I hope that maybe If I duplicate it here, I will get my answer sooner :)
I have a file:
/Users/danylo.volokh/test/test_bash_script.sh
Content is very simple:
#!/usr/bin/env bash
echo "-- print from script"
I'm in folder "danylo.volokh"
This command runs fine:
Danilos-MacBook-Pro:~ danylo.volokh$ test/test_bash_script.sh
-- print from script
But if I try to run in with absolute path I get an error:
Danilos-MacBook-Pro:~ danylo.volokh$ /test/test_bash_script.sh
-bash: /test/test_bash_script.sh: No such file or directory
I want to run a command with absolute path from any folder and get the script to be executed.
Your path in incorrect. You should run:
/Users/danylo.volokh/test/test_bash_script.sh
/test/test_bash_script.sh looks for the file from the root directory! Your path should be from the root, not from the current directory.
Try /Users/danylo.volokh/test/test_bash_script.sh.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I've been playing around with getting crontab to run a tar command on a scheduled basis however it appears to not actually run the task at the intervals at all.
The line of code I've put into my crontab file is as follows.
1 * * * * tar cvf backup.tar . >> ~/testcron.log
The tar command works by itself if I run it in terminal so I'm not sure why this doesn't run.
Thanks
There are two things here which I can imagine being problematic:
If this is part of a file in /etc/crontab.d or part of /etc/crontab, cron expects a user name in the 6th column. So it would be something along the lines of:
1 * * * * root tar cvf backup.tar . >> ~/testcron.log
You might want to replace . with a proper absolute path. I would not be sure what the current directory is when cron executes the cronjob, so just use an absolute path.
Unable to post as a comment
cron PATH variable may be different from your user PATH variable
If this is the case, you will either have to specify the absolute path to the tar executable or export your local PATH to the crontab
More information here
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
Here is my crontab entry:
* * * * * /home/ec2-user/Test/test_thing.sh
Here is the script, test_thing.sh:
echo "asdf" >> ./bla.txt
When I run it manually, it does generate the "bla.txt" file. However, it does not automatically do so (create the "bla.txt" file within the /Test/ directory) with the crontab.
I have also checked my /var/log/cron file and I see that it is executed every minute, but not sure if it's running into an error or not.
If it is important, I am running this on an Amazon ec2 server, specifically the Amazon Linux AMI.
Edits:
I have also done chmod +x test_thing.sh to make sure it is executable.
The cronjob runs from home directory by default. So you should see the file to be created under /home/ec2-user or /root if you run it by root account.
If you need generate the new file with the nominate path, one way is to use absolute path as #yftse said. The other way is
* * * * * cd /home/ec2-user/Test/; bash /home/ec2-user/Test/test_thing.sh
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
When I execute my cron manually everything seems to work. However when it runs by cron it seems to run twice. In my deployment script I have the following two lines to add my crons:
/usr/bin/crontab -l | { /bin/cat; /bin/echo "* 3 * * * /etc/app/execute.py"; } | /usr/bin/crontab -
/usr/bin/crontab -l | { /bin/cat; /bin/echo "* 0,2,4,6,8,10,12,14,16,18,20,22 * * * /etc/app/solr.py"; } | /usr/bin/crontab -
Is there any reasonable reason why my CRON might be running twice on my debian server? I have no idea what might be causing this or how to debug it.
In my Crontab I have this:
* 3 * * * /etc/app/execute.py
* 0,2,4,6,8,10,12,14,16,18,20,22 * * * /etc/app/solr.py
You can debug this by adding something like
; echo $(date) ; echo "Cron line one" >> /root/cronlog
That way you can see which line was executed when.
Also, how do you edit your cronjobs? With "crontab -e" or by directly editing the files? If you edit the files directly (which I don't recommend), then please compare the content of the files with the output of "crontab -l".