0

I am trying to schedule a backup script using a combination of cronjob, 'tar, and upload to an HPSS using htar utilities. I have set absolute paths in the crontab for all commands needed in the script, but, the script still fails. A sample of the error I'm getting is below. The exit code I get from the script is 72, which is critical OS file missing. I know the file exists in the specified directory.

If I run the script from the terminal (without cronjob), it works just fine.

How can I make the script work with a cronjob?

The crontab file looks like this:

PATH=/root/bin:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin:/usr/local/sbin
* * * * * /bin/sh /home/user/backup/script.sh

The error I'm getting looks like this:

Beginning backup of the server
Beginning htar...
INFO: I/O error occurred, and error -2 trying to stat file upload.tar
INFO: Retrying after I/O error at archive file offset 0
INFO: I/O error occurred, and error -2 trying to stat file upload.tar
INFO: Retrying after I/O error at archive file offset 0
INFO: I/O error occurred, and error -2 trying to stat file upload.tar
INFO: Retrying after I/O error at archive file offset 0
INFO: I/O error occurred, and error -2 trying to stat file upload.tar
INFO: Retrying after I/O error at archive file offset 0
72

A snippet of the script I am running looks like this

#!/bin/bash 
log=path_to_log_file
home_source=path_to_home
backup_source=path_to_backup

echo "Beginning backup of server" >> $log
sudo /usr/bin/tar -cf $backup_source/home.tar.gz $home_source

echo "Beginning htar..." >> $log
/usr/local/bin/htar -cvf "upload.tar" $backup_source/'home.tar.gz' >> $log

RETVAL=$?

echo $RETVAL >> $log
5
  • You're missing the absolute path for upload.tar.
    – waltinator
    Dec 22 '20 at 7:08
  • I believe upload.tar is just to upload that file to the default directory on the HPSS server.
    – hello
    Dec 22 '20 at 7:13
  • The same error still exists.
    – hello
    Dec 22 '20 at 7:33
  • Does the user have permission to write upload.tar in the working directory that cron gives the script? If you need to write to a specific directory, either use an absolute pathname for the archive file, or cd to a known location in the script. If this tries to store the archive on some other server (I've never seen htar before), then ask the admin of that server whether you have permission to store data there or whether the disk is full.
    – Kusalananda
    Dec 22 '20 at 7:51
  • According to what seems to be the htar manual, you should be able to get more debug output with -d N (where N is some digit between 1 and 5).
    – Kusalananda
    Dec 22 '20 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.