mv duplicating directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting mv duplicating directories
# 8  
Old 08-13-2011
Problem is still happening :/
I wish hitting it with a bigger stick would work!
# 9  
Old 08-13-2011
With set -x and "echo" you can see very easy what's wrong with your script.
Code:
#!/bin/bash
set -x
d="/home/scadmin/cpbackup/daily"
db="$d/*.tar.gz"

for f in $db
do
        f=$(basename $f)
        user=${f%%.*}
        o=`grep "^$user:" /etc/trueuserowners`
        owner=${o#* }
        if [ ! -d "$d/$owner" ]; then
                echo mkdir $d/$owner/
        fi
       echo mv -f $f $d/$owner/
done

You don't need at all all this "_". You don't export these variables, so they can't interfere with anything. The shell is noisy enough to add more.
# 10  
Old 08-14-2011
Well the script ran wrong again last night regardless of the changes. Removing the _ also broke the mv statement as $_f and $f were two different values. What I can see is that the if statement checks for the directory without a trailing slash whilst the mkdir statement runs with a trailing slash. I've added the trailing slash to see if that makes a different.

Its annoying that the script works fine when you run it from the console but screws up from cron overnight.
# 11  
Old 08-15-2011
This is still being a pig. It works perfectly fine when run from the command line. With set -x on I get the output emailed over and when run from cron it does the check to see if the directory exists and then goes right ahead and creates the directory regardless.

Next try, removing the double quotes from the if statement..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Duplicating and changing sh file

Hello, I have a file named file_1.sh that I want to duplicate into file_2.sh, file_3.sh,..., etc. I also need to change the text within each file so that it would fit the file name. For example, in file_1.sh there is a command to save some output as 'output_1.txt', and also there is an input... (3 Replies)
Discussion started by: haguyw
3 Replies

2. UNIX for Dummies Questions & Answers

duplicating a line

I have a text file which is the results of running a tests hundreds of times. For simplicity let's say that each test consists of 5 lines of text numbered 1-5 e.g. 1 aaa aaa aaa 2 bbb bbb bbb 3 ccc ccc ccc 4 ddd ddd ddd 5 eee eee eee 1 aaa aaa aaa 2 bbb bbb bbb 3 ccc... (4 Replies)
Discussion started by: millsy5
4 Replies

3. UNIX for Dummies Questions & Answers

Duplicating MAC linux or net?

hi guys I have a IBM eServer BladeCenter HS12 with Linux Red Hat 5.4 installed on it, it is using Bonding. ifcfg-bond0 DEVICE=bond0 BOOTPROTO=none ONBOOT=yes TYPE=Ethernet IPADDR=x.x.x.x NETMASK=x.x.x.x GATEWAY=x.x.x.x USERCTL=no IPV6INIT=no PEERDNS=no BONDING_OPTS="miimon=80... (1 Reply)
Discussion started by: karlochacon
1 Replies

4. Red Hat

Duplicating ethernet speed

Hi guys, Suppose you have a server with two ethernet cards (1GB each) and each cards are connecting to two different switches cisco 3750. My question is: How can I setup my server's network interfaces to increase the throughput up to 2GB? is it possible? If not, do you know another way to up... (3 Replies)
Discussion started by: iga3725
3 Replies

5. UNIX for Dummies Questions & Answers

remove duplicating lines

Hi, i have a webserver logfile and want to count how many page views there have been. I was thinking about removing lines that begin with the same user and same date&time, because it indicates they were just looking at one page and multiple hits were counted. My question is how do I do this?... (6 Replies)
Discussion started by: JudithBorg
6 Replies

6. HP-UX

duplicating ignite tapes

I have a B180L controller running HP-UX 10.2 with an internal DDS2 tape drive and an external Surestore DDS (24gb) tape drive. I want to make duplicate copies of ignite tapes from one tape drive to another. What is the best way to do this? (1 Reply)
Discussion started by: garyb
1 Replies

7. Post Here to Contact Site Administrators and Moderators

Sorry for duplicating posts

SORRY FOR DUPLICATING POSTS, COULD U JUST REMOVE THE FIRST ONE. Thank u. (1 Reply)
Discussion started by: vrguha
1 Replies

8. Shell Programming and Scripting

duplicating 1st row of data

Hi, I have data in the following format: data1 data2 data3 data4 data5 data6 data7 data8 data9 data10 I require the final output to be: data1 data1 data1 data1 i only require the 1st line but I need to replicate it in n rows where n is the number of rows where data... (4 Replies)
Discussion started by: ReV
4 Replies
Login or Register to Ask a Question