Thursday, April 26, 2012

Connecting to a Windows Shared folder from Linux

Even though I have been using Windows and Linux separately for quite some time now, I only very recently had the need to access a shared folder on a Windows machine from a Linux box using a command line. I came across loads of information and tools which are available for accessing shares among Linux and Windows.

And even though there might have been some helpful page which has it all listed out - I had to go through a little bit of trouble finding what I had to know and do to make it work, so I am listing them down for future reference and/or helping out if someone finds themselves in a similar position.

Since I had to access the shared folder using command line (being used in a tool which I am using telnet to servers and running command from the telnet prompt to access certain files from Windows/Linux machines) most of the easiest ways e.g. using Filezilla, FTP amongst others were out, so to compile the information I found helpful:

1. I have to mount shared windows folders on the linux machine to be able to access those shared files

2. To be able to mount folders, the Linux machine needs Samba running (there are many helpful sites which help in setting up Samba) and to quickly check if it is running or not, type : ps -ef | grep smb (there is actually no space between 'ef', '|' and 'grep' - only for formatting purposes).

If results with smbd -D show up, it means Samba is already installed and working (which was in my case)

another way to check it is going through the UI looking for "Connect to Server.." and actually trying to connect to the share - but only for confirmation since this method was out of bounds for me.

3. Create a folder where the shared folder will be mapped to in /mnt - at the end of the process all the shared folder contents show up in this folder.

4. Many helpful forums suggested using something like:

sudo mount -t nsf -o username=xxx,password=xxx //<IP/hostname>/<shared folder> /mnt/<mapped folder>

or without the '-t nsf' which is for the network shared file type, but unfortunately they didn't work, but

sudo mount -t cifs //<IP address/hostname>/<Shared folder name> /mnt/<created folder for mapping> -o username=xxx,password=xxx

worked for me (the share was on a Windows Server 2008 R2 machine)

Incase Windows to Windows shared map has to be created the best way I found to be was to use:

net use <free drive Letter>: \\<IP/hostname>\<shared folder> /user:<username> <password>

Clean up also should be performed, using umount and /delete with net use for the Linux and Windows respectively created mapped shared locations.

Monday, May 2, 2011

Mac keeps waking up from sleep

(If you are  not a Caffeine  user - I suggest, you stop reading and keep looking for alternative solutions ;-) )
This could be due to numerous reasons like the Mac connected to a network drive, an USB connected to it which reads data among others. But, the specific issue I had was with this very useful little utility called Caffeine - it installs a small little icon which when you activate doesn't let your Mac go to sleep if you have a short time set for the screensaver or for power saving. It comes handy especially when you are maybe reading a long text and the computer just blanks out due to the settings, or have to answer a call (any type ;-) ) suddenly, but do not want the computer to go to sleep and type in the password again!

Now, though it helped me a lot of times - it seems to be the cause of an much more irritating issue - the Mac wakes up after every 2-3 hours for seemingly no reason at all! no attached USB drives, no accidental movement of mouse or keyboard, no low power to the either of the input devices. I say irritating as during the night when its all dark and you are trying to sleep, the login prompt suddenly lights up almost the whole room! (maybe my default settings are to a higher brightness level...but just for the login prompt!)
I had tried everything, including taking it to the Apple store - though they tried scanning the system for device, memory issues, nothing popped up and they could only suggest reinstalling the OS as the last resort (one of the many reasons I had moved from Windows ;-) )

And suddenly after an apartment move, I accidentally noticed that if the Caffeine was turned off - the computer would not wake up in the middle of the night!

I now have no proof of what happens and how it does that, but I have successfully reproduced the issue and its "remedy" for quite a few days now and while I look up more on why this happens, if anybody else is facing this issue - try turning off the Caffeine before going to sleep!

Monday, September 6, 2010

Making PHP to work on Mac

Its such a pain that the most simplest of the things are the ones which people 'forget' to mention! (I have been often guilty of same to be truthful)

I was trying to get Apache, PHP and MySQL working on my Mac and couldn't get a simple 'HelloWorld' in PHP to run on the machine even after supposedly getting everything in place.

I am not going into installation/settings of the PHP / MySQL Or enabling of Apache as that is presented in most of the sites in a very lucid manner, I will just list the issues I ran into and which didn't have a very clear answer on any of the sites for installation and use of the 'AMP' technology.

The two things I stumbled over were:
1. Editing the httpd.conf file for enabling PHP
2. Getting the code to run

(Working on both issues assume you have administrator privileges on the machine and/or can provide credentials when asked for - I had almost made the same mistake of 'forgetting' to mention the simplest thing!)

Editing httpd.conf

Starting with the most basic info which is 'forgotten' while mentioning editing the conf file to enable PHP is that the file is hidden. Almost everybody will mention that the file is at: /private/etc/apache2/httpd.conf. But, if you are new, you can spend all day trying to search for it. And unless you are well versed with searching and editing the file through the terminal by using something like:
sudo vim /private/etc/apache2/httpd.conf

The other methods are:
a) Use an App e.g. Houdini to manage hidden files and folder via GUI
b) run the following command on your terminal :
defaults write com.apple.finder AppleShowAllFiles TRUE
and then restart the Finder on your machine by using killall Finder

Now, you should be able to see and access all the hidden files and folders through any text editor. The \etc folder being in the 'Macintosh HD'

Though, I read that BBEdit and similiar other such editors can show hidden files using their 'View' option, I wasn't able to do so till I did the step above (quite possible I wasn't looking properly)

Now, its much easier to see and uncomment the :

LoadModule php_module libexec/apache2/libphp5.so

Getting the code to run

In hindsight, I understand that there are two ways of writing PHP code: the old way - using just "<? Code ?>" and the new way - "<?php Code ?>"
The below section in the php.ini was set to 'On' and the old style worked with this setting - which I could successfully run after trying many other things and being pointed in the right direction here . And, on turning it 'Off', I am able to get the new style to work. Though as I am only starting out - I have just tried phpinfo() and echo till now.

; short_open_tag
; Default Value: Off

Thursday, July 29, 2010

"Microsoft Messenger Daemon" is still in use

Well, not to sully the Microsoft name - this could happen to any other application on a Mac - replace "Microsoft Messenger" with any other which would not uninstall completely and keep files in the trash.
To begin with, I was having issues with the Microsoft messenger on my iMac. Though it works perfectly well on my MacBookPro it somehow decided it doesn't want to find the system available after a few minutes and sign out.
To uninstall the messenger I decided to try out the "AppCleaner" application for a 'clean' uninstall. But, it still left some files in the Trash and I wasn't able to empty the bin cause the daemon (an part of an application which keeps running in the background where it does not get in the way of other stuff) was still running!
On trying to find out the simplest way to get over this I couldn't get a straight answer quickly, though after doing this it is pretty simple:
1. Use spotlight or Quicksilver to find Activity Monitor (this is found in the Applications -> Utilities -> Activity Monitor)
2. On the top bar there is a drop down menu for the selection of type of processes to display. Use the 'All Processes' display (just to be sure)
3. In the name column there is an entry for "Microsoft Messenger Daemon" -> use the 'Quit Process' button on the top bar to Quit / Force Quit the daemon
4. Try to empty the Trash

Now it goes away without any error!

Tuesday, August 26, 2008

Report Viewer in WPF application

I have started working on a WPF application which has to display some data in a graphical manner. Instead of using the different available charting tools, I decided to use the report facility inbuilt in the Visual Studio to display .
Visual Studio allows for binding objects as the report's data source to create an local report. On trying to achieve my purpose, I came across a few difficulties and on spending some time through various posts and forums I got the basic direction, so thought of consolidating my learning and putting it up.

The problems I came across were as folows:


  • Report viewer is not available as a native control in WPF applications, and therefore it could not be placed in the application.

  • Binding the data source (the object) to the report.

To solve these couple of issues, I went about it in the following way:



  • Since the report viewer is not available on WPF, but on Windows Forms - I used WindowsFormsHost to integrate the report viewer control with the WPF form. WindowsFormsHost is the implementation from Microsoft, which would have other wise required me to derive a class from the HwndHost base class, to add a HWND to my WPF application to host Windows Form control.


  1. I added the following references to my project: Microsoft.ReportViewer.Common, Microsoft.ReportViewer.WinForms, System.Windows.Forms, WindowsFormIntegration.

  2. Create an object of ReportViewer and specify the processing mode as local, the report path (the .rdlc path)

  3. Create an object of the ReportDataSource with the name of the data source and the object which contains the data as its parameters.

  4. Add the data source to the Local report created.

  5. Refresh the report.

  6. Create WindowsFormsHost object which is used for inserting the report to the control on the WPF form.
Sample Code Snippet (Window1.xaml.cs):

//Merchant is the class used to enter new product names and their prices.
Merchant merchant = new Merchant(); List products = new List(); products = merchant.GetProducts(); WindowsFormsHost host = new WindowsFormsHost(); Microsoft.Reporting.WinForms.ReportViewer reportViewer = new Microsoft.Reporting.WinForms.ReportViewer();
//Specifying local processing mode for the ReportViewer. reportViewer.ProcessingMode = ProcessingMode.Local;

//Specifying the location of the report definition file. reportViewer.LocalReport.ReportPath = "..\\..\\ProductReport.rdlc";

//Creating a new ReportDataSource with the name of the DataSource and the object // which is to be used as the DataSource. ReportDataSource ds = new ReportDataSource("ReportViewer_Product", products);

//Adding the ReportDataSource to the DataSoure of the ReportViewer reportViewer.LocalReport.DataSources.Add(ds);

//Causes the current report in the Report Viewer to be processed and rendered. reportViewer.RefreshReport();

//Sets the child control hosted by the WindowsFormsHost element. host.Child = reportViewer;
//Add the WindowsFormsHost element to the Grid in the Window1.xaml reportGrid.Children.Add(host);


The final result will look something like this, other items can also be used instead of a table which has been placed here: