0

I am new to shell scripting. I am trying to work through this.

> script to execute in cron (util.sh)
#!/bin/sh
HOST='ahostname'
PORT='3306'
USER='auser'
PASS='apassword'
DB='adatabase'
. /mnt/stor/backups/backup.sh

(I also tried source /mnt/stor/backups/backup.sh)

 > script to execute (backup.sh)

When backup.sh is called (it does get called) it appears to simply be parsed and not executed. So no matter what I put in it I get messages like:

/mnt/stor/backups/backup.sh: line 8: date: command not found
/mnt/stor/backups/backup.sh: line 8: mysqldump: command not found
/mnt/stor/backups/backup.sh: line 8: tar: command not found
/mnt/stor/backups/backup.sh: line 8: rm: command not found

The idea is to have a domain localized file, execute it with variables, and call a master script that uses the variable to do the dirty work. Because of limitations with one of my hosts and multiple domains this is the best method.

3
  • 1
    Most likely the sub-shell has a much different PATH than the parent shell. Try adding absolute paths to the commands, e.g. /bin/rm, /bin/tar, etc... Commented Jan 25, 2012 at 16:07
  • Looks like the PATH isn't properly set for cron's commands. If that's the case, using absolute pathnames to your commands (date, tar, etc.) or setting a PATH in backup.sh might help. Commented Jan 25, 2012 at 16:08
  • Looks even like something is actively zapping or sabotaging your PATH - basic commands like rm should certainly be available even with a limited PATH. Commented Jan 25, 2012 at 20:43

2 Answers 2

1

The script with the Problem seems to be /mnt/stor/backups/backup.sh. Try setting the PATH to include all the usual directories with binaries, so the script can find its tools. Or, even better, change /mnt/stor/backups/backup.sh and use absolute paths in the commands like /bin/rm instead of just 'rm'.

Sign up to request clarification or add additional context in comments.

Comments

1

When running from cron, you can't rely on any variables that are normally in your login shell's profile (e.g.: PATH, CLASSPATH, etc). You have to set explicitly what you need. In your case, i'm guessing that it's the lack of a PATH variable that's causing your troubles.

It's also good practice to put full paths to the programs you're executing from an unattended script, just to make sure you really are going to run that specific command, i.e., don't rely on the path.

So instead of

date

for example, use

/bin/date

etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.