Thursday, September 26, 2013

Ubuntu: Mount remote directories on a local machine


Today I'm searching for a way to mount a remote directory on my local machine, such that it acts like a local machine. The sole reason is to run the remotely compiled code locally.
I've found a nice article on it and would like to blog it here.
Here we go:
  • Install SSHFS:
sudo apt-get install sshfs
  • Add root to the fuse group: 
sudo adduser root fuse 
  • Create the local backup director

mkdir backup
  • Then mount the remote /home directory to backup:
sshfs -o idmap=user <username>@<remote system's ip>:/home backup
  • Let's check if the remote directory got mounted to /backup:
mount
df -h
  • To unmount the directory
fusermount -u backup
Check the backup folder to see your remote directory...

Source: howtoforge

Tuesday, September 24, 2013

Java : Redirect/Write console output to a file

java
Sometimes we would like to save the output from console into a file and to do this we use some stream writer/reader to read from console and write to a file.

But this can be done in much easier way as follows. Add the following code at the beginning of the program:
PrintStream out = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);
Now the default behaviour of out is changed to PrintStream out, and the output is redirected to the file provided above.

Edit:
To reset the standard behaviour, add the following code
System.setOut(stdout);