LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-17-2015, 06:37 PM   #1
SCSIraidGURU
Member
 
Registered: Oct 2014
Posts: 69

Rep: Reputation: Disabled
Error message access a Ubuntu 15.04 box from Windows 7


I am writing a C# application that reads all the directories and files on my Ubuntu web site and copies the changed files to my eSata drive on my workstation.

This is the code that reads all files and directories in my www folder.

System.IO.DirectoryInfo file1 = new System.IO.DirectoryInfo(pathA);
IEnumerable<System.IO.FileInfo> list1 = file1.GetFiles("*.*", System.IO.SearchOption.AllDirectories);

This is the error on my workstation accessing the web site after a few minutes.

A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll. Additional information: The specified network name is no longer available. f there is a handler for this exception, the program may be safely continued.

Any ideas on what is causing the network name to not be available. I can see the files on my Windows 7 workstation.

http://www.scsiraidguru.com/CSharp/CopyChange.html

Last edited by SCSIraidGURU; 05-17-2015 at 06:47 PM.
 
Old 05-18-2015, 01:19 PM   #2
Ihatewindows522
Member
 
Registered: Oct 2014
Location: Fort Wayne
Distribution: Ubuntu 16.04 LTS
Posts: 616
Blog Entries: 2

Rep: Reputation: 166Reputation: 166
Make sure the file permissions allow you to view the files in Windows. Keep in mind that Windows freaks out when exposed to UNIX permissions/file namings. A VBScript may be able to do this more efficiently, IDK, I haven't used VB in years.
Also you might want to download Ubuntu and try accessing your site from the live disk.
 
Old 05-18-2015, 03:14 PM   #3
SCSIraidGURU
Member
 
Registered: Oct 2014
Posts: 69

Original Poster
Rep: Reputation: Disabled
It seems like a network timeout connection issue. It happens but I can go into drive W:\, maps to \\ubuntu\www, and I can see everything fine. Samba is configured properly. User had administrator rights on both Windows and Ubuntu. I might see if I can write code to list the socket and see if its released properly. It could be the socket is still open and did not shut down. If I can determine the socket that is opened each time and add a kill socket command to close it. Than might help.
 
Old 05-23-2015, 10:50 AM   #4
Ihatewindows522
Member
 
Registered: Oct 2014
Location: Fort Wayne
Distribution: Ubuntu 16.04 LTS
Posts: 616
Blog Entries: 2

Rep: Reputation: 166Reputation: 166
Ummm...I still don't think you completely understand UNIX permissions...
http://www.ibm.com/developerworks/li...pic1-v3-104-5/

It doesn't matter if you're an administrator on Windows or not. The Windows kernel does not support UNIX permissions, and the only way to fix this is to make sure the SMB share is on a FAT or NTFS filesystem that doesn't support UNIX permissions OR make sure the permissions on all the files is/are 777 at all times.
 
Old 05-23-2015, 11:41 AM   #5
SCSIraidGURU
Member
 
Registered: Oct 2014
Posts: 69

Original Poster
Rep: Reputation: Disabled
I will reviewed the document. I changed the permissions to 777. Copy program ran once and copied a few changed files over. I will do some more testing thanks for the help.
 
Old 05-26-2015, 08:56 AM   #6
SCSIraidGURU
Member
 
Registered: Oct 2014
Posts: 69

Original Poster
Rep: Reputation: Disabled
I set the rights to var/www. First run, worked. Second run, same error. It is like a process is locking those files and not releasing them. I wonder if their is a file lock during the copy process. It seems to release after 2 minutes. My problem is writing code and testing and waiting the 2+ minutes between tests.
 
Old 05-26-2015, 11:54 AM   #7
SCSIraidGURU
Member
 
Registered: Oct 2014
Posts: 69

Original Poster
Rep: Reputation: Disabled
I am going to check to see if files are locked during the copy process. I am also looking at the code to see if the file exists and how to compare source length and destination length in the program.


11down voteaccepted There is the infamous lsof:
sudo lsof /var/lib/dpkg/lock
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
aptitude 4974 root 3uW REG 8,23 0 815673 /var/lib/dpkg/lock
In this case aptitude is using the file. You should use root in case you are not sure which user is locking the file. It's useful for a bunch of things too, sadly it doesn't come installed with Ubuntu, so you have to install it first.
For the rest of mortals, there's the fuser command. This is peculiar since it only returns the PID instead of the name of the process:
~ sudo fuser /var/lib/dpkg/lock
/var/lib/dpkg/lock: 4974
Here it says that the file and PID, which is 4974, so we must investigate who is:
~ ps 4974
PID TTY STAT TIME COMMAND
4974 pts/1 Sl+ 0:06 aptitude
 
Old 05-28-2015, 08:56 AM   #8
Ihatewindows522
Member
 
Registered: Oct 2014
Location: Fort Wayne
Distribution: Ubuntu 16.04 LTS
Posts: 616
Blog Entries: 2

Rep: Reputation: 166Reputation: 166
Changing the permissions just once won't stop them from being changed all the time. On my Rackspace server, I have a script running that constantly makes sure the permissions are 777. Rather insecure, yes. Able to access your files when you need them, you bet.

Code:
#!/bin/bash
#using my home folder as the example here
main () {
chmod -R 777 ~/*
wait 5
#tilde represents home folder, forward slash represents a directory change, and the astriek is of course a wildcard.
main
}

if [[ $USER == root ]] ; then
     main
else
     echo "Permission denied"
fi
As long as you have a strong password, you should be as secure as you can.
A technique I use is to swipe on your keyboard. You get a very cryptic looking password.
Here's an example: 9ol.*IK<7ujm4rfvTGB6yhn (987456, some I held down the shift key)
Test your password ideas here.
On one of my mediocre passwords, it says "It would take about 7023002971067 years to crack your password."

Quote:
In this case aptitude is using the file. You should use root in case you are not sure which user is locking the file. It's useful for a bunch of things too, sadly it doesn't come installed with Ubuntu, so you have to install it first.
Ubuntu does have aptitude, just under another name. apt-get is what is almost always used on Ubuntu and Debian. The solution should be simple enough, just make sure aptitude finishes before you try to run it again.

Last edited by Ihatewindows522; 05-28-2015 at 10:33 AM.
 
Old 05-28-2015, 09:14 AM   #9
SCSIraidGURU
Member
 
Registered: Oct 2014
Posts: 69

Original Poster
Rep: Reputation: Disabled
I think we are getting side tracked. The C# program reads a list of all the files from var/www and compares it to my eSATA backup. This is causing a file lock that is stopping the program. I can open the W: and run dir/s in Windows. I can see and access all the files. So it is not permissions stopping it. The error is a file lock. Since I am logged in with the same user I know who the user is. What I need is to determine the process that is locking the file and how long it locks them for. If I kill the process the program might stop running. So I need to determine how long the process locks for and add a pause into my application at the correct place. I did write a pause into the program for other parts. I need to find time to run the C# program and run the code to see the processes and locked files. The part of the C# program with the problem is reading the files and directories into a list. Another error is the files can't be found because of a lock. I wait 2 minutes I can access them. I did consider breaking the program into 3 parts running separate to get around it.
 
Old 05-28-2015, 10:32 AM   #10
Ihatewindows522
Member
 
Registered: Oct 2014
Location: Fort Wayne
Distribution: Ubuntu 16.04 LTS
Posts: 616
Blog Entries: 2

Rep: Reputation: 166Reputation: 166
What is the exact error message? Screenshot would be great.
 
Old 05-28-2015, 10:58 AM   #11
SCSIraidGURU
Member
 
Registered: Oct 2014
Posts: 69

Original Poster
Rep: Reputation: Disabled
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll Additional information: The specified network name is no longer available. If there is a handler for this exception, the program may be safely continued. [QUOTE]

The C# code is http://www.scsiraidguru.com/CSharp/CopyChange.html

The specified network name is no longer available is caused by file lock on creating the lists. This is a known error caused by file locking. I added in pauses and increased the read ahead cache. I am looking at increasing the RAM to 4GB and allocating 1GB on each drive for read ahead. I did consider writing a loop that checked for files being available before continuing. var/www is 100+ directories, 25,000+ files and 220 GB in size. Copying files from it to my workstation gets a similar file lock using Xcopy. The reason for this program is so I don't burn up the hard drives copying 220GB of files each time. Most of the files don't change. So I wanted to write a C# backup program to create new directories, copy changed and new files to a backup drive. It is a good way to learn C#.

Quote:
Console.WriteLine("Pause 10 seconds");

System.Threading.Thread.Sleep((int)System.TimeSpan.FromSeconds(10).TotalMilliseconds);

Console.WriteLine("Done pausing");



System.IO.DirectoryInfo dirfile1 = new System.IO.DirectoryInfo(pathA);

IEnumerable<System.IO.DirectoryInfo> dirlist1 = dirfile1.GetDirectories("*.*", System.IO.SearchOption.AllDirectories);

Console.WriteLine("Step 4 Dir path A");

Console.WriteLine("Pause 5 seconds");

System.Threading.Thread.Sleep((int)System.TimeSpan.FromSeconds(5).TotalMilliseconds);

Console.WriteLine("Done pausing");

// These lines find all the files

// Take a snapshot of the file system.

System.IO.DirectoryInfo file1 = new System.IO.DirectoryInfo(pathA);

IEnumerable<System.IO.FileInfo> list1 = file1.GetFiles("*.*", System.IO.SearchOption.AllDirectories);

Console.WriteLine("Step 1 files path A");
 
Old 06-03-2015, 11:37 AM   #12
SCSIraidGURU
Member
 
Registered: Oct 2014
Posts: 69

Original Poster
Rep: Reputation: Disabled
How can I turn off the web site and turn it back on. The file locks could be from the web site. I want to turn off the web site services before the backup runs and then enable them after.
 
Old 06-03-2015, 12:27 PM   #13
Ihatewindows522
Member
 
Registered: Oct 2014
Location: Fort Wayne
Distribution: Ubuntu 16.04 LTS
Posts: 616
Blog Entries: 2

Rep: Reputation: 166Reputation: 166
I assume you using Apache for this?
 
Old 06-03-2015, 12:31 PM   #14
SCSIraidGURU
Member
 
Registered: Oct 2014
Posts: 69

Original Poster
Rep: Reputation: Disabled
Sorry, Apache is what installs by default in Ubuntu.
 
Old 06-03-2015, 12:50 PM   #15
SCSIraidGURU
Member
 
Registered: Oct 2014
Posts: 69

Original Poster
Rep: Reputation: Disabled
How do I move this to Programming? Thanks for moving it.

Last edited by SCSIraidGURU; 06-04-2015 at 11:01 AM.
 
  


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
Error Message When re-installing windows OVER ubuntu pjfunk2k Linux - General 2 07-14-2010 06:44 PM
I get an error message while trying to install vb (Virtual Box) thewhitelion Linux - Software 1 04-04-2007 03:48 AM
Remote Access to Windows Box hkillen Linux - Networking 4 09-20-2006 09:01 AM
shell error messages not displayed as a message box!!! user222 Linux - General 10 10-25-2004 02:11 AM
how do I access a fricken windows box hugosoto Linux - Networking 5 11-27-2002 04:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:37 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