Difference between using shell or cron to execute a script

Hi!

Maybe i am here in the wrong section for the problem, but let me try to explain. I have the following simple backup script, as a solution till the final backup solution is online. Unfortunatly it will only work when executed manually. When i set up a cron job to execute the script, only the mysql service is stopped and restarted. There is no backup after the cron job, either executed as normal user or root.
Where is my mistake?

#!/bin/sh
archive1="/adm/backup/files/dfs_full_backup_`date +%d-%m-%y`.tar.gz"
archive2="/adm/backup/files/dfs_diff_backup_`date +%d-%m-%y`.tar.gz"
file="/adm/backup/filelist"
wochentag="`date +%a`"
if [ $wochentag == "So" ]; then

    # Fullbackup
    timestamp="`/bin/date +%Y-%m-%d\ %H:%M:%S`";echo $timestamp > /adm/backup/.lastfullbackup
    sudo /etc/init.d/mysql stop
    sudo /bin/tar -czPf $archive1 -T $file > /adm/backup/log/log`/bin/date +%Y%m%d`
    sudo /etc/init.d/mysql start
    scp -i /home/admin/.ssh/id_dsa $archive1 admin@xx-xxxx-xxxx.xx.xxx.xxx:$archive1
    find /adm/backup/files/* -mtime +14 | xargs rm -f

else

    #Differenzbackup
    sudo /etc/init.d/mysql stop
    sudo /bin/tar -chvzPf $archive2 --newer=".lastfullbackup" -T $file > /adm/backup/log/log`/bin/date +%Y%m%d`
    sudo /etc/init.d/mysql start
    scp -i /home/admin/.ssh/id_dsa $archive2 admin@xx-xxxx-xxxxx.xx.xxx.xxx:$archive2
    find /adm/backup/files/* -mtime +14 | xargs rm -f

fi

exit 0

 cat /adm/backup/filelist 
/var/lib/mysql
/srv/www/htdocs

Is that script in a users crontab, or in the global? if it's the latter, sudo might complain. Check the mails sent by cron for any error messages.

I can't see any error in the log. Here the output when executing as a regular user:

Oct 27 14:58:01 dfs /usr/sbin/cron[10562]: (admin) CMD (/adm/backup/backup.sh)
Oct 27 14:58:01 dfs sudo:    admin : TTY=unknown ; PWD=/home/admin ; USER=root ; COMMAND=/etc/init.d/mysql stop
Oct 27 14:58:02 dfs sudo:    admin : TTY=unknown ; PWD=/home/admin ; USER=root ; COMMAND=/bin/tar -chvzPf /adm/backup/files/dfs_diff_backup_27-10-09.tar.gz -
-newer=.lastfullbackup -T /adm/backup/filelist
Oct 27 14:58:02 dfs sudo:    admin : TTY=unknown ; PWD=/home/admin ; USER=root ; COMMAND=/etc/init.d/mysql start

Using it as root without sudo:

Oct 28 12:17:01 dfs /usr/sbin/cron[2853]: (root) CMD (/adm/backup/backup.sh)

Did you check the mails of user root? cron (usually) sends any error messages (even those not in syslog) via mail to the user who's running a command (in this case: root).

Yes, but the error was too simple to see it. :wink:
I hadn't used the absolute path for the time file (.lastfullbackup), so it was not found.
Thx