I hope you can help me...

I made a perl and bash script to make a backup of my firewalls and tranfers via tftp


 perl /deploy/scripts/backups/ > /dev/null 2>&1
 perl /deploy/scripts/backups/ > /dev/null 2>&1

so this tranfers the file to my tftp directory /tftpboot/

ls -l /tftpboot/
total 532
-rw-rw-rw- 1 tftp tftp 209977 jun  6 14:01
-rw-rw-rw- 1 tftp tftp 329548 jun  6 14:02

my questions is how to improve my script to moving this files dynamically to another folder based on the name (in this case on the ip address)

for example: move to /deploy/backups/

is that the answer to this surely was on Google, but wanted to know if there was a particular solution to this request and also learn how to do :)


  • is this intra network? Or is this ftp server far away from you? – Virusboy Jun 6 '14 at 17:46

Simply transform the filename into data space, then manipulate it to extract the information you want, then use the information. NOTE: For production, use a more constrained file match than /tftpboot/*.cfg

for file in /tftpboot/*.cfg ; do
    ipaddr=$( echo "$file" | cut -d/ -f3 | cut -d_ -f1 )  
    [ -d /deploy/backups/${ipaddr} || mkdir -p /deploy/backups/${ipaddr}  
    mv --verbose "$file" /deploy/backups/${ipaddr}/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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