Solved cron starting but not executing rsync

Hello.

I've placed rsync.sh as an executable script in /etc/rsync.sh

The script looks like this:
#!/bin/bash
/usr/local/bin/rsync -a /usr/home/hack /mnt/bak

tail /var/log/cron looks alright?
Feb 23 16:43:00 astro /usr/sbin/cron[34574]: (root) CMD (/etc/rsync.sh)
Feb 23 16:44:00 astro /usr/sbin/cron[34906]: (operator) CMD (/usr/libexec/save-entropy)
Feb 23 16:45:00 astro /usr/sbin/cron[35219]: (root) CMD (/usr/libexec/atrun)
Feb 23 16:45:00 astro /usr/sbin/cron[35220]: (root) CMD (root /usr/libexec/atrun)

But rsync never launches. Please wha am I doing wrong here?

Update: Can't get this cron to run as root. It only runs as user.
 
There should not be any /bin/bash in a FreeBSD configuration. Try replacing the shebang line, which says #!/bin/bash in your script, with #!/bin/sh or even with #!/usr/local/bin/bash if you have the bash port installed.
 
Hi,

From the log entries, it looks like you have modified /etc/crontab to run /etc/rsync.sh as root.

As pointed out above, /bin/bash does not usually exist on FreeBSD systems.

Because Linux people grow up with bash, they tend not to know the difference between bash and Bourne shell.

Hence many Linux people use /bin/bash, when a simple Bourne shell would do (to complicate things /bin/sh is expected to be a POSIX Bourne shell, but is actually bash on some Linux variants).

Your script above does not need bash. Any Bourne compatible shell would do -- /bin/sh would work on any Unix-like system.

So, in /etc/rsync.sh, change "#!/bin/bash" to "#!/bin/sh".

Then, make sure that /etc/rsync.sh is executable ("chmod +x /etc/rsync.sh"), and, as root, type:

/bin/sh
set -x
/etc/rsync.sh
set +x
exit


What happens?

As an aside, the usual approach when you really need bash is to:
  1. Install the bash package ("pkg install bash").
  2. Ensure "/usr/local/bin" is in the default PATH.
  3. Change the first line of each bash script from "#!/bin/bash" to "#!/usr/bin/env bash".
Cheers,
 
In addition to what Vull said:



What crontab is that command in? How did you edit that crontab? Maybe you could post a copy of that crontab file here.
The crontab belongs to the root user (su & crontab -e)
# /etc/crontab - root's crontab for FreeBSD
#
# $FreeBSD$
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
#
#minute hour mday month wday who command
#
*/5 * * * * root /usr/libexec/atrun
34 16 * * * root /usr/local/bin/rsync -a /usr/home/hack /mnt/bak
43 * * * * /etc/rsync.sh
Update:
changing /bin/bash into /bin/sh executes the script when run from the root crontab. Thank you.
 
I've made tons of mistakes here. I'm very grateful for your help.
I don't need bash. I don't need Linux. I'm a BSD convert now.

Funny thing is though.
I can't get the root crontab
to run the rsync syntax
Code:
34 16 * * * root /usr/local/bin/rsync -a /usr/home/hack /mnt/bak
 
Mostly agreeing with you, just one minor nit:

Change the first line of each bash script from "#!/bin/bash" to "#!/usr/bin/env bash".
Or change it to "#!/usr/local/bin/bash". The difference between the two is subtle, but important. Using env works well for interactive use, and it makes scripts portable between OSes where bash is installed in different places: As long as bash is on the path, it will be found by env. But the explicit description of where the bash executable is stored is more robust for non-interactive use, where you can't be sure that the path is set to include the executable. For example, I'm not user that /usr/local/bin is in the default path (in the default environment) for cron on all OSes; I think it is on FreeBSD, but when writing crontab entries I'm not going to rely on "I think it is". So for industrial-strength system administration, I use the explicit full path, both in the shebang line and in crontab.
 
I can't get the root crontab
to run the rsync syntax
Code:
34 16 * * * root /usr/local/bin/rsync -a /usr/home/hack /mnt/bak

Hi, the format of /etc/crontab is different to individual user crontabs. /etc/crontab requires a user to be nominated for each command. Individual user crontabs do not. Delete "root".
 
Sorry, but if you are annoyed at that, you will be annoyed at a lot of FreeBSD things.

In FreeBSD, only the stuff that comes from the basic part of the operating system is in /bin, /sbin/, /usr/bin/, configured via /etc, and so on. Everything that is from an optional package is stored in /usr/local/... Since bash is not needed for the basic FreeBSD install, it does belong in /usr/local. By the way, the same applies to python: it is also in an optional package, and also in /usr/local.

If you look around various Unix-style operating system families, they all have different file system hierarchies, and different traditions or conventions for where to install optional software packages. I've dealt with /opt, /usr/lpp, and a whole lot of other places.
 
Good question. I'm not sure that I even see the point of having a statically linked version of any interestingly complex shell at all. I might see the point of having a simple emergency shell that's statically linked, for single-user boot in case the shareable libraries are damaged. But for FreeBSD, bash is not that.

The description of the bash-static package doesn't help, lacking detail. Still, if it is a package, it doesn't belong in /bin.
 
Bash is a third party application, it has no place in /bin or /usr/bin. Those are for the base OS only.
 
Back
Top