-   Linux - Newbie (
-   -   Moving files linux to windows (

trickydba 01-20-2017 08:38 AM

Moving files linux to windows
First I would like to show my WORKING code:

# Append current date to all files
for file1 in $(ls *[a-z].xlsx)
basefile1=$(echo $file1 |awk -F. '{print $1}')
current_time=$(date "+_%m%d%Y.xlsx")

mv $file1 ${basefile1}${current_time}

# Create variable
current_folder=$(date "+%m%d%Y")

# Make folder
mkdir "$current_folder"

# Change permissions of folder
chmod 777 /dir1/dir2/dir3/reports/${current_folder}

# Move files into folder labelled with the current date
mv *.xlsx "${current_folder}"

# Move whole folder to local shared Windows folder
mv "${current_folder}" //dir1/dir2/dir3/reports/dir4/dest_folder

Everything was working fine but now all of the sudden after the sysadmins did 'maintenance' the whole script works , but now it only moves the biggest file in the folder and nothing else. I personally think the disk is running out of space.Is something wrong with my script? Like I stated earlier it was running perfectly fine and moving ALL files in the folder just fine.

michaelk 01-20-2017 08:50 AM

Is /dir1/dir2/dir3/reports/dir4/dest_folder a remote or local directory? You should be able to see its disk space usage using the df command.

trickydba 01-20-2017 09:00 AM

76% used. It's a remote Windows shared folder

trickydba 01-20-2017 09:02 AM

It all started with the so called maintenance done, then I was not able to 'rm' an archive file. Now everything works BUT it only moves the biggest file

michaelk 01-20-2017 09:09 AM

Can you move the other files manually? It probably is something the sysadmins changed.

trickydba 01-20-2017 09:16 AM

If done manually yes I can move everything just fine. I was just told they did some patching

rtmistler 01-20-2017 09:19 AM

I feel what might be useful here is to see more data, on the data. Debug mode for the script as it finds files because perhaps there's a new issue which is causing only certain files to be found. Then additional information on the input and expected output. Which is to say, "new files are xxxx, yyyy, zzzz, and their sizes are .... (for instance show an ls -l output of it all), and then cite what is supposed to happen, and finally describe what did happen.

I realize you did say this, however you said it in general versus using the specific data, or some edited representation of the data so as to not reveal information you have to protect.

trickydba 01-20-2017 09:25 AM

Well it's only .xlsx files in a current dated folder. I'm using Oracle EDQ to create these reports and send them to a shared Windows folder. For a week everything was working ok until the sysadmins did some patching. I am very reluctant to change ANY of my code since it was working ok until THEY did some patching. Yes because of my job I can't really give all the info, but I did my best to provide you with a clear picture of what is happening. I feel things just dont happen for a week then all of the sudden mess up.I think it's clear that whatever 'patching' they did messed things up. If you look at my comments in my code, if someone would like to provide more efficient code Im open to that too

rtmistler 01-20-2017 09:35 AM

My point is that the commands likely are not affected too much by their upgrades. In fact, their upgrades were to Windows, correct?

Your script, correct me on this point, is run by Linux or cygwin running attached to this drive or machine?

Either case, the script fundamentals are very simple: for loop, ls command, mv command, chmod command.

Therefore the directory structure is a possible item in question.

As I cited, it is sometimes difficult to give true examples, however there are a few ways I'd approach this, and they go back to the same recommendations for when you developed your script:
  1. set -xv within the script to debug it and other methods
  2. Manual entry of the commands which do not appear to be working to debug what is happening
  3. Getting "representative" information for the data, such as an ls -l where you remove all the attributes for owner, group, filename, and only show that it is "a" xlsx file of a certain size.

trickydba 01-20-2017 09:39 AM

My point is that the commands likely are not affected too much by their upgrades. In fact, their upgrades were to Windows, correct?.....This is correct

Your script, correct me on this point, is run by Linux or cygwin running attached to this drive or machine?.....It is ran by Linux

Out of curiosity, why would the directory structure cause an issue?

rtmistler 01-20-2017 09:41 AM

I have no idea what "//dir1/dir2/dir3/reports/dir4/dest_folder" represents, except that you physically have the directory structure named: //dir1/dir2/dir3/reports/dir4/dest_folder

Why is there a double // before all that? I do not feel it is required, unless this is something you've already tested and discovered that it was required?

grail 01-20-2017 10:54 AM

I have plenty of issues with the script as it stands, but as that is a second issue, please follow the suggestion of using set-xv to get output which can be diagnosed.

trickydba 01-20-2017 12:01 PM

@grain...what issues do you have with the script??? Can you please provide some code that would be better?

nodir 01-20-2017 12:28 PM

From the top of my head:
Using a "for ls " combination is never a good idea:

The command date is in the loop, which means the time can change during the loop

I would test if the folder exists already, before you create it

I would always make the script exit, if a mkdir or mv fails (like in "mkdir foobar || exit").

I would use ParameterExpansion.

Not saying such is better or something is wrong. Only saying what comes to my mind.
I fiddled a bit with it, but can't test it well. I am beginner. Anyway here would be my approach, but on a pastebin site (so it doesn't look like a proposed solution). Don't get me wrong, don't be angry at me. :-) Only ideas. Look at it, perhaps it contains useful for you. Else ignore

trickydba 01-20-2017 01:05 PM

@nodir...You are no beginner posting suggestions like that. I am the beginner.

Can someone please post code that would do the same as my code above, but better. I am a beginner and the only way I got to the code I provided was by help from someone else on this site which was working just fine. I've ran out of ideas. Meanwhile Ill do the 'set -xv' suggestion.

All times are GMT -5. The time now is 12:08 AM.