Announcement

Collapse
No announcement yet.

strange output from cronjob for backup script

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    strange output from cronjob for backup script

    hi all,
    I'm very confused as to why I am getting this error message when I run a cronjob for a backup script I'm working on:
    Code:
    mkdir: cannot create directory `/home/erind/socprojects_backups/10_19_2011\r/\r': No such file or directory
    The script leading up to this error is:
    Code:
    # ./SocProjects/cronjobs/weekly_fullbackup.sh
    # Backup script for SOC project files and mysql database, to be executed weekly.
    #################################
    # Assign DTG and Date variables #
    # to $a & $b respectively    #
    #################################
    a=$(date +%T-%d_%m_%Y)
    b=$(date +%m_%d_%Y)
    ########################################
    # Backup Site Directory - files and db #
    ########################################
    ### echo command states the name of the directory being made for the current backup,
    ### where the filesystem/code and database backup copies will go. The mkdir command
    ### actually creates the directory.
    echo "mkdir /home/erind/socprojects_backups/".$b
    mkdir /home/erind/socprojects_backups/$b/
    I'm really confused because I wrote this script modeled after another backup script that does not have this problem. I don't get why the output is showing me "\r/\r"

    Any help appreciated!
    System Information<br />Distro: Ubuntu 11.04<br />KDE: Platform Version 4.6.2<br />Grub: 0.97-29ubuntu61.1 GRand Unified Bootloader (Legacy version)<br /><br />PC Hardware:<br />laptop HP Pavilion dv6<br />CPU: AMD Turion(tm) II P520 Dual-Core Processor<br />GPU: ATI Technologies Inc M880G [Mobility Radeon HD 4200]

    #2
    Re: strange output from cronjob for backup script

    This works for me. I think you might have some embedded, non-displayable characters in the that assigns $b? Did you cut and paste this from something another file? I typed in the part that assigns $b and issued a mkdir ~/$b/ and it created the directory without issue.

    Comment


      #3
      Re: strange output from cronjob for backup script

      Hmm.

      I created the following script to test:

      Code:
      b=$(date +%m_%d_%Y)
      echo "mkdir /home/greenman/junk/" .$b
      mkdir /home/greenman/junk/$b/
      Note there is no "junk" directory
      Running it produces:

      Code:
      greenman@Wolfenstein:~$ ./junk.sh
      mkdir /home/greenman/junk/ .10_19_2011
      mkdir: cannot create directory `/home/greenman/junk/10_19_2011/': No such file or directory
      which is right -- cannot create a directory under a non-existent directory.

      \r is a carriage return character, don't know where the double CR is coming from. Can't reproduce the error here.

      I concur there must be some embedded characters somewhere.
      We only have to look at ourselves to see how intelligent life might develop into something we wouldn't want to meet. -- Stephen Hawking

      Comment


        #4
        Re: strange output from cronjob for backup script

        I cloned another .sh file in my Netbeans IDE and edited there and then used Filezilla to move it to the appropriate cronJobs folder on my server.

        Do you know how I can determine if I have any of these hidden embedded characters?

        Also when I delete the trailing / from the directory name it works, but creates a directory with ?? at the end of the name.

        i.e. 10_18_2011??

        Should I just try creating a new file in vi on the server and hand typing it out?
        System Information<br />Distro: Ubuntu 11.04<br />KDE: Platform Version 4.6.2<br />Grub: 0.97-29ubuntu61.1 GRand Unified Bootloader (Legacy version)<br /><br />PC Hardware:<br />laptop HP Pavilion dv6<br />CPU: AMD Turion(tm) II P520 Dual-Core Processor<br />GPU: ATI Technologies Inc M880G [Mobility Radeon HD 4200]

        Comment


          #5
          Re: strange output from cronjob for backup script

          i used :
          Code:
          sed -n 'l' myfile.txt
          and it showed me that I have "\r$" at the end of every line
          System Information<br />Distro: Ubuntu 11.04<br />KDE: Platform Version 4.6.2<br />Grub: 0.97-29ubuntu61.1 GRand Unified Bootloader (Legacy version)<br /><br />PC Hardware:<br />laptop HP Pavilion dv6<br />CPU: AMD Turion(tm) II P520 Dual-Core Processor<br />GPU: ATI Technologies Inc M880G [Mobility Radeon HD 4200]

          Comment


            #6
            Re: strange output from cronjob for backup script

            Originally posted by erinsaurus87
            i used :
            Code:
            sed -n 'l' myfile.txt
            and it showed me that I have "\r$" at the end of every line
            My guess is the file was created on a Windows machine and uploaded in binary instead of ASCII mode.

            Windows adds a carriage return + a line feed to the end of every line in a text file while *nix adds only the line feed. If your FTP client uploads a text file created on a Windows machine in binary mode you get the carriage returns - uploading in ASCII mode strips those carriage returns out.
            we see things not as they are, but as we are.
            -- anais nin

            Comment

            Working...
            X