What is wrong with the entry in crontab?

What is wrong with the entry in crontab??
Write this:
@midnight bash /bin/bash ~/backup.sh > /tmp/tmp.cron

In /tmp/tmp.after running cron doesn't write anything down.
June 14th 19 at 19:59
4 answers
June 14th 19 at 20:01
Solution
1. Check the execute bit (x) in the script ~/backup.sh team
ls-la ~/backup.sh
if there is no execute bit (x), then put:
chmod a+x ~/backup.sh

2. Check the cron logs
cat /var/log/syslog | grep CRON | grep backup.sh

3. Always! I repeat, Always specify the full path to the startup script, i.e.
@midnight bash /full/path/backup.sh >/var/log/backup.log 2>&1


4. I recommend to organize the output of debugging information and error handling in log on script in crontab to write the design:
@midnight bash /full/path/backup.sh >/dev/null 2>&1

to redirect all output and errors to /dev/null

if you write a construct like this
@midnight bash /full/path/backup.sh >/dev/null
only the output stream is redirected to /dev/null if an error occurs the execution of the script, then cron will notify the root user by email (if properly configured mailing server)
I've added him right to the execution. Zero sense.
Now, as a test, gave it permissions 777.
cat /var/log/syslog | grep CRON | grep backup.sh
There is only
Oct 5 10:10:01 Samba CRON[15847]: (root) CMD (bash /home/user/backup.sh > /tmp/tmp.cron)
- pearl_Web commented on June 14th 19 at 20:04
then

Log in as user bash
su -l bash -s /bin/bash
Try to run the script without redirecting output
/home/user/backup.sh
See the result
Then redirect
/home/user/backup.sh > /tmp/tmp.cron
See the result in the console and in /tmp to/tmp.cron

Write the test results here.

My assumptions and recommendations:
1. Most likely the user with no bash access to the directory /home/user/
2. Permissions 777 on the file backup.sh excessive, avoid this, 755 is enough. Also make the file owner the root user (chown root:root /home/user/backup.sh) - this will help to avoid changes to all who are not falling.
3. Do not store your scripts to be used in cron or run from the console to their personal directory, this is /usr/bin and /usr/sbin - nikita.Schoen45 commented on June 14th 19 at 20:07
What is written as the first line in the file /home/user/backup.sh ?
I recommend to write
#!/usr/bin/env bash
or
#!/bin/bash - nikita.Schoen45 commented on June 14th 19 at 20:10
,
there is written
#!/bin/bash - pearl_Web commented on June 14th 19 at 20:13
And in what still was the problem? - nikita.Schoen45 commented on June 14th 19 at 20:16
June 14th 19 at 20:03
Why do you bash /bin/bash ?
Enough bash ~/backup.sh > /tmp/tmp.cron
bash is the user to run as. - pearl_Web commented on June 14th 19 at 20:06
As it is not logical to call a user as a system command.
As an option, create a separate file
crontab-u user_name file - nikita.Schoen45 commented on June 14th 19 at 20:09
June 14th 19 at 20:05
I would instead ~ the exact way.
I initially had the full path. Also not run( - pearl_Web commented on June 14th 19 at 20:08
June 14th 19 at 20:07
The user bash on the server exists?

upd. try this:
0 0 * * * %username% %absoljutnye скрипту%/backup.sh > /tmp/tmp.cron


in the script the first line must be specified interpreter #!/bin/bash
The user is bash. - pearl_Web commented on June 14th 19 at 20:10
#!/bin/bash in the script specified.
Yes, and if you manually run the script then everything works without problems. - nikita.Schoen45 commented on June 14th 19 at 20:13

Find more questions by tags Ubuntu ServerCronLinuxbash