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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
01-20-2017, 09:38 AM
|
#1
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Rep:
|
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.
|
|
|
01-20-2017, 09:50 AM
|
#2
|
Moderator
Registered: Aug 2002
Posts: 26,347
|
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.
|
01-20-2017, 10:00 AM
|
#3
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep:
|
76% used. It's a remote Windows shared folder
|
|
|
01-20-2017, 10:02 AM
|
#4
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep:
|
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
|
|
|
01-20-2017, 10:09 AM
|
#5
|
Moderator
Registered: Aug 2002
Posts: 26,347
|
Can you move the other files manually? It probably is something the sysadmins changed.
|
|
|
01-20-2017, 10:16 AM
|
#6
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep:
|
If done manually yes I can move everything just fine. I was just told they did some patching
|
|
|
01-20-2017, 10:19 AM
|
#7
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,914
|
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.
|
|
|
01-20-2017, 10:25 AM
|
#8
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep:
|
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
|
|
|
01-20-2017, 10:35 AM
|
#9
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,914
|
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: - set -xv within the script to debug it and other methods
- Manual entry of the commands which do not appear to be working to debug what is happening
- 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.
|
01-20-2017, 10:39 AM
|
#10
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep:
|
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?
|
|
|
01-20-2017, 10:41 AM
|
#11
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,914
|
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.
|
01-20-2017, 11:54 AM
|
#12
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,028
|
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.
|
01-20-2017, 01:01 PM
|
#13
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep:
|
@grain...what issues do you have with the script??? Can you please provide some code that would be better?
|
|
|
01-20-2017, 01:28 PM
|
#14
|
Member
Registered: May 2016
Posts: 222
Rep:
|
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 01:30 PM.
|
|
1 members found this post helpful.
|
01-20-2017, 02:05 PM
|
#15
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep:
|
@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 08:14 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|