Cronjob output not working [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have this cronjob:
#!/bin/bash
YEAR=`date +%Y`
MONTH=`date +%m`
DAY=`date +%d`
mkdir -p $YEAR/$MONTH/$DAY
mysqldump -uroot -p1234 locatari > $YEAR/$MONTH/$DAY/backup.sql
And I want to run this at each let's say 3 minutes. I tried with each of these crontab
commands and none on them seems to work:
3 * * * * /usr/bin /home/rome/cronjob/back.sh > /home/rome/cronjob
3 * * * * /home/rome/cronjob/back.sh/
3 * * * * exec `/bin/bash /home/rome/cronjob/back.sh`
3 * * * * /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1
I only made it run when I did:
bash back.sh
All worked as expected with the bash command, what is wrong to my cron scheduler? Problem is that with the crontab command, I can't see my output, it only works with bash command.
bash cron
closed as off-topic by roaima, andcoz, slm⦠Jun 22 at 0:35
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." â roaima, andcoz, slm
add a comment |Â
up vote
1
down vote
favorite
I have this cronjob:
#!/bin/bash
YEAR=`date +%Y`
MONTH=`date +%m`
DAY=`date +%d`
mkdir -p $YEAR/$MONTH/$DAY
mysqldump -uroot -p1234 locatari > $YEAR/$MONTH/$DAY/backup.sql
And I want to run this at each let's say 3 minutes. I tried with each of these crontab
commands and none on them seems to work:
3 * * * * /usr/bin /home/rome/cronjob/back.sh > /home/rome/cronjob
3 * * * * /home/rome/cronjob/back.sh/
3 * * * * exec `/bin/bash /home/rome/cronjob/back.sh`
3 * * * * /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1
I only made it run when I did:
bash back.sh
All worked as expected with the bash command, what is wrong to my cron scheduler? Problem is that with the crontab command, I can't see my output, it only works with bash command.
bash cron
closed as off-topic by roaima, andcoz, slm⦠Jun 22 at 0:35
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." â roaima, andcoz, slm
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have this cronjob:
#!/bin/bash
YEAR=`date +%Y`
MONTH=`date +%m`
DAY=`date +%d`
mkdir -p $YEAR/$MONTH/$DAY
mysqldump -uroot -p1234 locatari > $YEAR/$MONTH/$DAY/backup.sql
And I want to run this at each let's say 3 minutes. I tried with each of these crontab
commands and none on them seems to work:
3 * * * * /usr/bin /home/rome/cronjob/back.sh > /home/rome/cronjob
3 * * * * /home/rome/cronjob/back.sh/
3 * * * * exec `/bin/bash /home/rome/cronjob/back.sh`
3 * * * * /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1
I only made it run when I did:
bash back.sh
All worked as expected with the bash command, what is wrong to my cron scheduler? Problem is that with the crontab command, I can't see my output, it only works with bash command.
bash cron
I have this cronjob:
#!/bin/bash
YEAR=`date +%Y`
MONTH=`date +%m`
DAY=`date +%d`
mkdir -p $YEAR/$MONTH/$DAY
mysqldump -uroot -p1234 locatari > $YEAR/$MONTH/$DAY/backup.sql
And I want to run this at each let's say 3 minutes. I tried with each of these crontab
commands and none on them seems to work:
3 * * * * /usr/bin /home/rome/cronjob/back.sh > /home/rome/cronjob
3 * * * * /home/rome/cronjob/back.sh/
3 * * * * exec `/bin/bash /home/rome/cronjob/back.sh`
3 * * * * /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1
I only made it run when I did:
bash back.sh
All worked as expected with the bash command, what is wrong to my cron scheduler? Problem is that with the crontab command, I can't see my output, it only works with bash command.
bash cron
edited Jun 21 at 13:08
asked Jun 21 at 12:43
Tatu Bogdan
84
84
closed as off-topic by roaima, andcoz, slm⦠Jun 22 at 0:35
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." â roaima, andcoz, slm
closed as off-topic by roaima, andcoz, slm⦠Jun 22 at 0:35
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." â roaima, andcoz, slm
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
None of your crontab
job entries matches what you typed at the command line
/usr/bin /home/rome/cronjob/back.sh
tries to run a program/usr/bin
, but that's a directory/home/rome/cronjob/back.sh/
tries to treat your script as a directoryexec `/bin/bash /home/rome/cronjob/back.sh`
tries to use the output of your program as a program name to run/bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1
this might work, except that you have thrown away all the output of the script, so you won't see any errors
Based on feedback from your comments it seems you probably want something like this (I've omitted /home/rome
because that is your home directory anyway):
*/3 * * * * cd cronjob && bash back.sh >back.log 2>&1
Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
â Tatu Bogdan
Jun 21 at 13:05
@TatuBogdan what directory do you run thebash back.sh
command from, when you do it yourself? (Your home directory? Somewhere else?)
â roaima
Jun 21 at 13:10
cd /home/rome/cronjob and then bash back.sh
â Tatu Bogdan
Jun 21 at 13:12
@TatuBogdan is/home/rome
your home directory? Also, have you looked in~/2018/06/21
for your dump file fromcrontab
?
â roaima
Jun 21 at 13:15
Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
â Tatu Bogdan
Jun 21 at 13:25
 |Â
show 1 more comment
up vote
2
down vote
Your cron schedule expression means "At every minute 3" => each hour.
Every 3 minutes would be:
*/3 * * * *
See this nice tool to check the expression.
Also only your last cron command will work. But I would not redirect the output to /dev/null
. If there are any problems with your script, it's difficult to debug.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
None of your crontab
job entries matches what you typed at the command line
/usr/bin /home/rome/cronjob/back.sh
tries to run a program/usr/bin
, but that's a directory/home/rome/cronjob/back.sh/
tries to treat your script as a directoryexec `/bin/bash /home/rome/cronjob/back.sh`
tries to use the output of your program as a program name to run/bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1
this might work, except that you have thrown away all the output of the script, so you won't see any errors
Based on feedback from your comments it seems you probably want something like this (I've omitted /home/rome
because that is your home directory anyway):
*/3 * * * * cd cronjob && bash back.sh >back.log 2>&1
Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
â Tatu Bogdan
Jun 21 at 13:05
@TatuBogdan what directory do you run thebash back.sh
command from, when you do it yourself? (Your home directory? Somewhere else?)
â roaima
Jun 21 at 13:10
cd /home/rome/cronjob and then bash back.sh
â Tatu Bogdan
Jun 21 at 13:12
@TatuBogdan is/home/rome
your home directory? Also, have you looked in~/2018/06/21
for your dump file fromcrontab
?
â roaima
Jun 21 at 13:15
Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
â Tatu Bogdan
Jun 21 at 13:25
 |Â
show 1 more comment
up vote
2
down vote
accepted
None of your crontab
job entries matches what you typed at the command line
/usr/bin /home/rome/cronjob/back.sh
tries to run a program/usr/bin
, but that's a directory/home/rome/cronjob/back.sh/
tries to treat your script as a directoryexec `/bin/bash /home/rome/cronjob/back.sh`
tries to use the output of your program as a program name to run/bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1
this might work, except that you have thrown away all the output of the script, so you won't see any errors
Based on feedback from your comments it seems you probably want something like this (I've omitted /home/rome
because that is your home directory anyway):
*/3 * * * * cd cronjob && bash back.sh >back.log 2>&1
Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
â Tatu Bogdan
Jun 21 at 13:05
@TatuBogdan what directory do you run thebash back.sh
command from, when you do it yourself? (Your home directory? Somewhere else?)
â roaima
Jun 21 at 13:10
cd /home/rome/cronjob and then bash back.sh
â Tatu Bogdan
Jun 21 at 13:12
@TatuBogdan is/home/rome
your home directory? Also, have you looked in~/2018/06/21
for your dump file fromcrontab
?
â roaima
Jun 21 at 13:15
Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
â Tatu Bogdan
Jun 21 at 13:25
 |Â
show 1 more comment
up vote
2
down vote
accepted
up vote
2
down vote
accepted
None of your crontab
job entries matches what you typed at the command line
/usr/bin /home/rome/cronjob/back.sh
tries to run a program/usr/bin
, but that's a directory/home/rome/cronjob/back.sh/
tries to treat your script as a directoryexec `/bin/bash /home/rome/cronjob/back.sh`
tries to use the output of your program as a program name to run/bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1
this might work, except that you have thrown away all the output of the script, so you won't see any errors
Based on feedback from your comments it seems you probably want something like this (I've omitted /home/rome
because that is your home directory anyway):
*/3 * * * * cd cronjob && bash back.sh >back.log 2>&1
None of your crontab
job entries matches what you typed at the command line
/usr/bin /home/rome/cronjob/back.sh
tries to run a program/usr/bin
, but that's a directory/home/rome/cronjob/back.sh/
tries to treat your script as a directoryexec `/bin/bash /home/rome/cronjob/back.sh`
tries to use the output of your program as a program name to run/bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1
this might work, except that you have thrown away all the output of the script, so you won't see any errors
Based on feedback from your comments it seems you probably want something like this (I've omitted /home/rome
because that is your home directory anyway):
*/3 * * * * cd cronjob && bash back.sh >back.log 2>&1
edited Jun 21 at 13:56
answered Jun 21 at 12:51
roaima
39.2k544105
39.2k544105
Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
â Tatu Bogdan
Jun 21 at 13:05
@TatuBogdan what directory do you run thebash back.sh
command from, when you do it yourself? (Your home directory? Somewhere else?)
â roaima
Jun 21 at 13:10
cd /home/rome/cronjob and then bash back.sh
â Tatu Bogdan
Jun 21 at 13:12
@TatuBogdan is/home/rome
your home directory? Also, have you looked in~/2018/06/21
for your dump file fromcrontab
?
â roaima
Jun 21 at 13:15
Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
â Tatu Bogdan
Jun 21 at 13:25
 |Â
show 1 more comment
Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
â Tatu Bogdan
Jun 21 at 13:05
@TatuBogdan what directory do you run thebash back.sh
command from, when you do it yourself? (Your home directory? Somewhere else?)
â roaima
Jun 21 at 13:10
cd /home/rome/cronjob and then bash back.sh
â Tatu Bogdan
Jun 21 at 13:12
@TatuBogdan is/home/rome
your home directory? Also, have you looked in~/2018/06/21
for your dump file fromcrontab
?
â roaima
Jun 21 at 13:15
Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
â Tatu Bogdan
Jun 21 at 13:25
Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
â Tatu Bogdan
Jun 21 at 13:05
Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
â Tatu Bogdan
Jun 21 at 13:05
@TatuBogdan what directory do you run the
bash back.sh
command from, when you do it yourself? (Your home directory? Somewhere else?)â roaima
Jun 21 at 13:10
@TatuBogdan what directory do you run the
bash back.sh
command from, when you do it yourself? (Your home directory? Somewhere else?)â roaima
Jun 21 at 13:10
cd /home/rome/cronjob and then bash back.sh
â Tatu Bogdan
Jun 21 at 13:12
cd /home/rome/cronjob and then bash back.sh
â Tatu Bogdan
Jun 21 at 13:12
@TatuBogdan is
/home/rome
your home directory? Also, have you looked in ~/2018/06/21
for your dump file from crontab
?â roaima
Jun 21 at 13:15
@TatuBogdan is
/home/rome
your home directory? Also, have you looked in ~/2018/06/21
for your dump file from crontab
?â roaima
Jun 21 at 13:15
Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
â Tatu Bogdan
Jun 21 at 13:25
Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
â Tatu Bogdan
Jun 21 at 13:25
 |Â
show 1 more comment
up vote
2
down vote
Your cron schedule expression means "At every minute 3" => each hour.
Every 3 minutes would be:
*/3 * * * *
See this nice tool to check the expression.
Also only your last cron command will work. But I would not redirect the output to /dev/null
. If there are any problems with your script, it's difficult to debug.
add a comment |Â
up vote
2
down vote
Your cron schedule expression means "At every minute 3" => each hour.
Every 3 minutes would be:
*/3 * * * *
See this nice tool to check the expression.
Also only your last cron command will work. But I would not redirect the output to /dev/null
. If there are any problems with your script, it's difficult to debug.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Your cron schedule expression means "At every minute 3" => each hour.
Every 3 minutes would be:
*/3 * * * *
See this nice tool to check the expression.
Also only your last cron command will work. But I would not redirect the output to /dev/null
. If there are any problems with your script, it's difficult to debug.
Your cron schedule expression means "At every minute 3" => each hour.
Every 3 minutes would be:
*/3 * * * *
See this nice tool to check the expression.
Also only your last cron command will work. But I would not redirect the output to /dev/null
. If there are any problems with your script, it's difficult to debug.
edited Jun 21 at 13:03
answered Jun 21 at 12:51
RoVo
83219
83219
add a comment |Â
add a comment |Â