Linux CRON help

vinbuckvinbuck Member Posts: 785 ■■■■□□□□□□
Need a little help with CRON and scripting.

I'm trying to automate ftp transfer of a dhcpd.conf and dhcpd.lease file by running commands in a scheduled cron job every night. What i can't seem to figure out is how to append the remote file name of each file with the current date so that i'm not overwriting the files each night.

I'd like to make the remote file name look something like this:

dhcpd.conf.01252011
dhcpd.leases.01252011

I'm sure this is a pretty simple operation with the right script/variable but i'm not much on linux scripting. Any ideas?
Cisco was my first networking love, but my "other" router is a Mikrotik...

Comments

  • sidsanderssidsanders Member Posts: 217 ■■■□□□□□□□
    what have you got so far?

    file names with date:
    dhcpconf=dhcpd.conf.`date '+%m%d%Y'`
    etc...

    or you can do that on the mv, or cp or whatever logic you are doing with the script.

    man date
    has info on the different output formatting available.

    for ftp, may i suggest using sftp? much more secure. didnt ask this up front: what are you trying to fix or set up? backup of a dhcp server?
    GO TEAM VENTURE!!!!
  • Forsaken_GAForsaken_GA Member Posts: 4,024
    The date command in backticks is what you're looking for.

    I'd recommend rsync for this over ftp, to be honest
  • NightShade03NightShade03 Member Posts: 1,383 ■■■■■■■□□□
    I'd recommend rsync for this over ftp, to be honest

    +1 rsync is awesome...
  • vinbuckvinbuck Member Posts: 785 ■■■■□□□□□□
    I guess I should lay out what I have to work with...

    I'm trying to back up dhcpd.conf and dhcp.leases from multiple Linux dhcp servers. The FTP server i'm going to is a Windows 2000 server that I have no ability to change or upgrade. I would love to use a linux server but it isn't an option right now.

    here is what i've done so far...it isn't pretty but it works for the time being.

    Cron job run at midnight

    cp /etc/dhcp/dhcpd.conf /etc/dhcp/archive/dhcpd.conf.$(date +%m%d%y)

    Cron job run at 12:05 am
    /etc/dhcp/./ftp.sh

    Where the contents of ftp.sh (slightly sanitized for the web) are

    ftp -n -i 192.168.201.100 <<EOF
    user anonymous user@user.com
    cd Linux_DHCP_backup
    cd dhcpd.conf
    lcd /etc/dhcp/archive
    mput *.*
    quit
    EOF

    I'll have to check on rsync and sftp to see if I can use them with a w2k server platform. I'm definitely open to other (i.e. better) methods of doing this.
    Cisco was my first networking love, but my "other" router is a Mikrotik...
  • MentholMooseMentholMoose Member Posts: 1,525 ■■■■■■■■□□
    If you don't need the local backups, you can simply upload the existing configuration file to a file with today's date on the server. In this case it would just need one cron job to run this script:
    #!/bin/bash
    HOST=192.168.201.100
    USER=anonymous
    PW=nobody@
    SOURCE=/etc/dhcp/dhcpd.conf
    DEST=Linux_DHCP_backup/dhcpd.conf/dhcpd.conf.`date +%m%d%y`
    ftp -ni $HOST <<EOF
    user $USER $PW
    put $SOURCE $DEST
    quit
    EOF
    exit
    
    MentholMoose
    MCSA 2003, LFCS, LFCE (expired), VCP6-DCV
  • sidsanderssidsanders Member Posts: 217 ■■■□□□□□□□
    copssh is a windows ssh/sftp server, and free. doesnt enable any users after install so it does not default to wide open remote terminal access to a server. can limit to only sftp as well.

    if this is from multiple machines you could consider putting the machine name into the dhcp* files, or tar them up using the date and hostname as the output file name.
    GO TEAM VENTURE!!!!
Sign In or Register to comment.