Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to fix this error I keep seeing, and I'm not sure why I'm seeing them. The script generates a list of files older than 7 days, then tars/gzips them into a backup directory. Finally it removes the files once the backup has completed successfully. I am encountering a weird error. The script is simple, most of it is to prevent the script from running twice or hanging, or it handles logging. The important code is between the asterisks.

#       Title:
#       Author:         Matthew Sarro
#       Date:           03/07/2012
#       Desc:           Backs up all files down the tree which are
#                       older than 7 days
DATE=`date +%F-%H%M`

exec 3<>$LOGFILE
exec >&3 2>&3

#define the name of the lockfile

# check for existing lockfile
if [ -e "$LOCKFILE" ]; then
# lockfile exists
        #check if file is readable
   if [ ! -r "$LOCKFILE" ]; then
      echo error: lockfile is not readable
      exit 1

#define PID as the process number in lockfile
   PID=`cat "$LOCKFILE"`
# check if process is signal-able and redirect stderr to /dev/null
   kill -0 "$PID" 2>/dev/null
#if process was signal-able echo an error
   if [ $? == 0 ]; then
      echo error: existing instance of this task is already running
      exit 1

# process that created lockfile is no longer running - delete lockfile
   rm -f "$LOCKFILE"
#check if lockfile deleted properly
   if [ $? != 0 ]; then
      echo error: failed to delete lockfile
      exit 1

# create lockfile containing current process ID
echo $$ >"$LOCKFILE"
if [ $? != 0 ]; then
   echo error: failed to create lockfile
   exit 1

#find all files older than 7 days and create a file list
find /root/testing/{MSP,CEMP} -mtime +7 -type f > /root/testing/fwdcleanuplogs/$DATE.list

#add all files from the file list into a tar.gz file
tar -czf /root/testing/backups/$DATE.tar.gz --files-from /root/testing/fwdcleanuplogs/$DATE.list

#delete all files from the file list off disk
rm -f `cat /root/testing/fwdcleanuplogs/$DATE.list`

# delete lockfile
rm -f "$LOCKFILE"
if [ $? != 0 ]; then
   echo error: failed to delete lockfile
   exit 1

exec 3>&-
exit 0

When I run the script, the following shows up in the generated log:

./ line 67: backups: command not found

I have no idea why this is showing up - I can't seem to figure it out. The code still executes brilliantly, but the error is driving me batty. I can't see anything in line 67 that would even remotely tell the OS that backups is a command.

Any advice would really be appreciated.

Edit: Before anyone notices: this is being done on a test VM, hence the usage of the root account :)

share|improve this question
up vote 4 down vote accepted

Your line 67 is ************************* which should really have a # at the beginning. The first * is being expanded by your shell and is picking up the file called backups in the current directory.

share|improve this answer
GAH! thank you so much, I can't believe I missed that. Very much appreciated – Matthew Mar 7 '12 at 20:44
+1 because I can relate – rlduffy Mar 7 '12 at 21:08

Use the -x option to bash to get a trace of what the script is doing. That'll give you a pretty good idea of where things are going bad.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.