Shell script and CRON issues

I wrote a backup script for our local dev server (running Ubuntu server edition 9.10), just a simple little script for tar and gzip local root and paste it into the backup folder. It works fine when I run:

$ bash backups.sh

but it does not work when I run it through crontab.

59 23 *  *  *  bash /home/vnc/backups/backup.sh >> /home/vnc/backups/backup.log 2> $1

I get an error

/bin/sh: cannot create : nonexistent

The script does tar.gz in the folder in which it is running (/ home / user1), but then tries to copy it to the mounted share (/ home / backups, which is really 192.168.0.6/backups) from the network drive using fstab. The installed share has 777 permissions, but the owner and group are different from those who run the script. I use bash to run a script instead of sh to get around another problem that I had in the past with "bad replacement" errors

The first 2 lines of the file

! /bin/bash

cd /home/vnc/backups

I probably did not provide enough information to fully respond to this post, but I can post additional information as necessary, but I do not know where to look further.

+3
source share
3 answers

The key is in the error message:

/bin/sh: cannot create : nonexistent

, "sh". Bourne , Bash. Bash, Bash, script.

:

#!/bin/bash

crontab :

* * * * * /bin/bash scriptname

crontab script .

+5

, , backups.sh, - cd /home/user1. crond script , , , , , .

id > /tmp/id.$$ - , , script.

+1

In crontab, just change 2> $ 1 to 2> & 1. I just did it myself. Thanks, Dennis Williamson.

+1
source

Source: https://habr.com/ru/post/1793554/


All Articles