Find the answer to your Linux question:
Results 1 to 8 of 8
Im fairly new to linux and know very little about it. I created a crontab entry: 30 7 * * * root cp -b /usr/local/minecraft_servers/backups/ /media/SAM750/backups/ and the same thing ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2013
    Posts
    7

    Crontab help


    Im fairly new to linux and know very little about it.

    I created a crontab entry:
    30 7 * * * root cp -b /usr/local/minecraft_servers/backups/ /media/SAM750/backups/
    and the same thing for www & teamspeak folders

    this works fine but i dont want it to ovewrite files that are already there.

    Is there a way to do this to make it just copy files over that aren't already in that directory.

    Any help with this would be appreciated, if i need another way to do this could you please dumb it down

    regards
    Stephen

  2. #2
    Linux Newbie blnl's Avatar
    Join Date
    Jan 2009
    Location
    The Netherlands
    Posts
    165
    In order not to overwrite the files you could write a bash script that is called from the crontab.

    In that case your crontab statement would look like this:
    Code:
    30 7 * * * root /home/userx/backups.sh
    In the script "backups.sh" you can add for example the date somewhere in the path name:
    Code:
    #!/ffp/bin/sh
    
    DATE=$(date +%Y%m%d)
    cp -b /usr/local/minecraft_servers/backups/ /media/SAM750/backups/${DATE}/
    Fedora_20@Dell_Latitude_E6410
    Ubuntu_14.04_LTS@HP_Compaq_DC7100

  3. #3
    Just Joined!
    Join Date
    Jan 2013
    Posts
    7
    Quote Originally Posted by blnl View Post
    In order not to overwrite the files you could write a bash script that is called from the crontab.

    In that case your crontab statement would look like this:
    Code:
    30 7 * * * root /home/userx/backups.sh
    In the script "backups.sh" you can add for example the date somewhere in the path name:
    Code:
    #!/ffp/bin/sh
    
    DATE=$(date +%Y%m%d)
    cp -b /usr/local/minecraft_servers/backups/ /media/SAM750/backups/${DATE}/
    did that as follows:
    * 15 * * * root /usr/local/minecraft_servers/backup.sh

    (didnt change this)
    #!/ffp/bin/sh

    DATE=$(date +%Y%m%d)
    cp -b /usr/local/minecraft_servers/backups/ /media/SAM750/backups/${DATE}/

    however at 3pm there was nothing copied

  4. #4
    Linux Newbie blnl's Avatar
    Join Date
    Jan 2009
    Location
    The Netherlands
    Posts
    165
    First make sure your scripts is executable.
    Code:
    chmod 777 /usr/local/minecraft_servers/backup.sh
    Also try executing the script manually to identify is the problem in the script itself or crontab definition.
    Code:
    sh /usr/local/minecraft_servers/backup.sh
    Fedora_20@Dell_Latitude_E6410
    Ubuntu_14.04_LTS@HP_Compaq_DC7100

  5. #5
    Linux Newbie blnl's Avatar
    Join Date
    Jan 2009
    Location
    The Netherlands
    Posts
    165
    There is indeed a mistake in the script. Sorry, I copy-pasted without thinking.

    Change the header
    Code:
    #!/ffp/bin/sh
    to
    Code:
    #!/bin/sh
    Of course, test if the the script works.
    If it works, stop reading here.
    -------------------------------------------------------------------------------------
    If not, chech if the "sh" exists
    Code:
    which sh
    If anything different than "/bin/sh" is given use that in the header of your script (do not forget #!).
    Fedora_20@Dell_Latitude_E6410
    Ubuntu_14.04_LTS@HP_Compaq_DC7100

  6. #6
    Just Joined!
    Join Date
    Jan 2013
    Posts
    7
    Quote Originally Posted by blnl View Post
    First make sure your scripts is executable.
    Code:
    chmod 777 /usr/local/minecraft_servers/backup.sh
    Also try executing the script manually to identify is the problem in the script itself or crontab definition.
    Code:
    sh /usr/local/minecraft_servers/backup.sh
    cp: omitting directory `/media/CardinalCraft/minecraft_servers/backups/'
    thats what i get when i try to run from terminal

    (ignore the address part as i just moved them and adjusted the backup.sh paths

  7. #7
    Just Joined!
    Join Date
    Jan 2013
    Posts
    7
    Quote Originally Posted by blnl View Post
    There is indeed a mistake in the script. Sorry, I copy-pasted without thinking.

    Change the header
    Code:
    #!/ffp/bin/sh
    to
    Code:
    #!/bin/sh
    Of course, test if the the script works.
    If it works, stop reading here.
    -------------------------------------------------------------------------------------
    If not, chech if the "sh" exists
    Code:
    which sh
    If anything different than "/bin/sh" is given use that in the header of your script (do not forget #!).
    did that and it came back with /bin/sh only

    pls read post above thats the error i get

    Thanks for the replies

  8. #8
    Linux Newbie blnl's Avatar
    Join Date
    Jan 2009
    Location
    The Netherlands
    Posts
    165
    Quote Originally Posted by Rebz01 View Post
    cp: omitting directory `/media/CardinalCraft/minecraft_servers/backups/'
    You get that because you are copying directory. cp will not copy directory tree unless specified explicitly.

    Try adding the -r switch in the line:
    Code:
     cp -rb /usr/local/minecraft_servers/backups/ /media/SAM750/backups/${DATE}/
    Fedora_20@Dell_Latitude_E6410
    Ubuntu_14.04_LTS@HP_Compaq_DC7100

Posting Permissions

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