LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-20-2017, 08:38 AM   #1
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Rep: Reputation: Disabled
Moving files linux to windows


First I would like to show my WORKING code:
Code:
# Append current date to all files
for file1 in $(ls *[a-z].xlsx)
do
basefile1=$(echo $file1 |awk -F. '{print $1}')
current_time=$(date "+_%m%d%Y.xlsx")

mv $file1 ${basefile1}${current_time}
done

# 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.
 
Old 01-20-2017, 08:50 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 18,914

Rep: Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849
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.
 
1 members found this post helpful.
Old 01-20-2017, 09:00 AM   #3
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
76% used. It's a remote Windows shared folder
 
Old 01-20-2017, 09:02 AM   #4
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
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
 
Old 01-20-2017, 09:09 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 18,914

Rep: Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849
Can you move the other files manually? It probably is something the sysadmins changed.
 
Old 01-20-2017, 09:16 AM   #6
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
If done manually yes I can move everything just fine. I was just told they did some patching
 
Old 01-20-2017, 09:19 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 7,992
Blog Entries: 13

Rep: Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443
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.
 
Old 01-20-2017, 09:25 AM   #8
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
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
 
Old 01-20-2017, 09:35 AM   #9
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 7,992
Blog Entries: 13

Rep: Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443
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.
 
1 members found this post helpful.
Old 01-20-2017, 09:39 AM   #10
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
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?
 
Old 01-20-2017, 09:41 AM   #11
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 7,992
Blog Entries: 13

Rep: Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443Reputation: 3443
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?
 
1 members found this post helpful.
Old 01-20-2017, 10:54 AM   #12
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,719

Rep: Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034
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.
 
1 members found this post helpful.
Old 01-20-2017, 12:01 PM   #13
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@grain...what issues do you have with the script??? Can you please provide some code that would be better?
 
Old 01-20-2017, 12:28 PM   #14
nodir
Member
 
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled
From the top of my head:
Using a "for ls " combination is never a good idea:
http://mywiki.wooledge.org/BashPitfa...8ls_.2A.mp3.29

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. http://mywiki.wooledge.org/BashFAQ/0...meterExpansion

---
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 http://paste.debian.net/909737/

Last edited by nodir; 01-20-2017 at 12:30 PM.
 
1 members found this post helpful.
Old 01-20-2017, 01:05 PM   #15
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving Windows files (user) files to Linux bmrzmr2 Linux - Newbie 3 11-13-2015 04:09 PM
Moving windows files to Linux rgwic Linux - Newbie 11 04-06-2014 02:36 AM
Moving FIles from Windows fileserver to Linux stgiaf Linux - Server 2 11-23-2013 05:31 PM
moving files from windows to linux...urgent samyakm Linux - Newbie 5 01-02-2005 02:56 AM
moving files between windows and linux endezeichen Linux - Software 4 11-19-2003 02:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration