![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]() |

|
| Linux and Unix Error ! Redhat,suse,centos,mandrake,Free BSD,Sun |
![]() |
|
Linux script needed for file moving and directory creating
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Administrator
Posts: 18,695
Join Date: Jan 2006
Rep Power: 10
IM:
|
BBB-00019-615619-65465183.pdf QLD-00123-698231-651321684321.pdf COW-00102-321583-48731.pdf Where the first set of digits (between the first and second dashes) is the "customer number". So in the first BBB example, 00019 is the customer number. I need a scrip that reads the /HOLD directory, finds the customer number (which will always be the 5th through 9th characters) and move it to the /CUSTOMER/CUSTNUM directory. So for the first BBB example, the file would be moved to /CUSTOMER/00019 directory. Here is the catch. I need the script to first check to see if the customer directory exists, and if it doesnt, it needs to CREATE the directory, THEN move the file into the the directory. |
|
|
|
|
|
|
|
|
#2 (permalink) |
|
Administrator
Posts: 18,695
Join Date: Jan 2006
Rep Power: 10
IM:
|
#!/bin/bash # set these to the appropriate directories HOLD=~/HOLD CUSTOMERS=~/CUSTOMERS for FILE in $HOLD/*; do # get the customer number CUSTNUM=`echo $FILE | awk -F\- {'print $2'}` # check if the customer dir exists, if not create it if [ ! -d $CUSTOMERS/$CUSTNUM ];then mkdir $CUSTOMERS/$CUSTNUM fi # move the file mv $FILE $CUSTOMERS/$CUSTNUM/ |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|