Find the answer to your Linux question:
Results 1 to 3 of 3
Ok, i've been messing around in debian the past few days, setting up programs like subversion, mysql and logrotate. The purpose of this script is to use subversion to backup ...
  1. #1
    Just Joined!
    Join Date
    Sep 2009
    Posts
    1

    bash script in debian

    Ok, i've been messing around in debian the past few days, setting up programs like subversion, mysql and logrotate. The purpose of this script is to use subversion to backup the binary logs. It runs in the cron every 2 hours or so (although I can't get my script to run properly atm, which is why i'm here).

    It also changes the filename to the format logfile-"current date" so as to keep it fairly sorted in subversion.

    Code:
    #!/bin/bash
    #change file name to Logfile'date'
    dt=`date +%y%m%d`
    if [ -f /tmp/test01/Logfile-$dt ]
    then
            cp mysql-bin.000001 /var/log/mysql/ Logfile-$dt /tmp/test01/
            svn commit /tmp/test01 --non-interactive -m "bi-hourly update of mysql binary logs"
            echo "File exists and was comitted."
    else
            cp mysql-bin.000001 /var/log/mysql/ Logfile-$dt /tmp/test01/
            svn add /tmp/test01/Logfile-$dt
            svn commit /tmp/test01 --non-interactive -m "creating new days binary log file"
            echo "File did not exist, copied mysql-bin000001 and created new days file"
    fi
    This is the error I get:

    Code:
    mv: missing destination file operand after `090921'
    Try `mv --help' for more information.
    I originally had the cp format in the form /directory/directory/file, and this resulted in the exact same error.

    This is really my first few forays into linux and bash scripting, so if its something completely obvious, my bad ^_^ (in-fact, probably the first script i've done using if/else) any help would be appreciated.

  2. #2
    Linux Newbie
    Join Date
    Jul 2005
    Location
    Australia (Down Under)
    Posts
    141
    Code:
    #!/bin/bash
    #change file name to Logfile'date'
    dt=`date +%y%m%d`
    if [ -f /tmp/test01/Logfile-$dt ]
    then
            cp /home/crazy/test.sh "/tmp/test01/Logfile-$dt"
            
            echo "File exists and was comitted."
    else
            cp /home/crazy/test.sh "/tmp/test01/Logfile-$dt"
            
            echo "File did not exist, copied mysql-bin000001 and created new days file"
    fi

    ive changed the directories, but i think that the problem was either having the file name then the directory or the fact that there were no double quotes('') around the destination.

    hope that helps
    Linux is the OS of tomorrow, Here today!!

  3. #3
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    Look at this line
    Code:
    cp mysql-bin.000001 /var/log/mysql/ Logfile-$dt /tmp/test01/
    What exactly did you want to achieve? I believe the extra space between /var/log/mysql/ and Logfile-$dt is what causes the error.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...