Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I hope you can help me...

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

#!/bin/sh 

 perl /deploy/scripts/backups/10.160.23.1.pl > /dev/null 2>&1
 perl /deploy/scripts/backups/10.160.23.2.pl > /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 10.160.23.1_20140606.cfg
-rw-rw-rw- 1 tftp tftp 329548 jun  6 14:02 10.160.23.2_20140606.cfg

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: 10.160.23.1_20140606.cfg move to /deploy/backups/10.160.23.1/

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 :)

Thanks!

share|improve this question
    
is this intra network? Or is this ftp server far away from you? –  Virusboy Jun 6 at 17:46

1 Answer 1

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

#!/bin/bash  
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}/
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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