Sep 252016
 

I’m just putting here this command to remember it next time when I need it.

Problem to be solved

When SD card of my photo camera is full I just upload the photos to my NAS server NSA320 . After that usually I do some cleanup and one of the steps is to move the video (there are not only photos)  files from the the photo/ directory to other location.

Until now I did this step manually, to save time I was thinking to make it automatic.

Solution

This is what I want to do:

  1. Get shell access on my NSA320 , to do this I’ve installed ffp (Fonz fun_plug). It is a collection of packages for NSA320 that includes a ssh server.
  2. After getting ssh access in step 1, I need to create a small scrip to move all the video files from $SOURCE_DIR to $DST_DIR. All video means files with next extensions:
    • .MOV (has to be no case sensitive)
    • .MPG/MP4 (has to be no case sensitive)
    • .AVI (has to be no case sensitive)

I’m using rsync command.

rsync -rav –remove-source-files –exclude ‘*’ –include ‘*/’ –include ‘*.[Mm][Oo][Vv]’ –include ‘*.[Mm][pP][4gG]’ –include ‘*.[Aa][Vv][Ii]’  –prune-empty-dirs $SOURCE_DIR  $DST_DIR

The meaning of the arguments:

  • -r = to go recursively on the entire $SOURCE_DIR
  • -a = archive mode, it means to preserve most of the attributes of the files. For me important was last modified time
  • -v = verbose; I just wanted to have a list with files that have been moved.
  • –remove-source-files = to remove from source dir the files that have been copied to destination.
  • –exclude ‘*’ = by default exclude all files; except the one passed to “–include” switches
  • –include ‘*/’ =  include directories in teh list of files that have to be moved
  • –include ‘*.[Mm][Oo][Vv]’ = include files with .MOV extension; no case sensitive. Similar for .MPG, .MP4, .AVI
  • –prune-empty-dirs = do not copy empty dirs from source to destination

At the end of the command you will noticed something like this:

sent 24287985339 bytes received 8458 bytes 12766356.79 bytes/sec
total size is 24511383985 speedup is 1.01

On my NSA320 it took few minutes to move ~23GB.

 Posted by at 10:18 AM
Jan 182014
 

Small tip for virtualbox: how you can enable copy (and paste) from host to guest and from guest to host.

Most when playing with virtual machines you would like to copy pieces of code from host machine to guest OS and vice versa.

By default after installing virtual box, this feature is not activated, but can be enabled very easy.
In the main menu of the windows where the guest OS is running is a submenu “Devices”.
Just select Devices -> Sharecropped -> Bidirectional ; like  in the picture bellow.

Virtualbox enable shared clipboard

Virtualbox enable shared clipboard

And now the copy -> paste should work without any problem.

E.g. you just found on the net an interesting piece of code browsing from host OS, but net is not enabled on the guest OS; now you can test it just doing copy->paste.

Keep in mind that this setting is for virtual machine. So, if you will play other image of a VM, you have to do the same settings.

 Posted by at 10:17 PM
Aug 232013
 

Few days ago I’ve installed VirtualBox from Oracle on my windows7 machine because I needed a linux where to play with apache webserver.

The instalation was very easy (I assume that internet is available on the host system :D)

  1. Installed VirtualBox
  2. Created a guest machine for Debian
  3. Downloaded Debian Netinstall Image; it is a small CD image which allow ou to install Debian via network. Just google for debian netinst iso , and you should get the latest version.
  4. Tell to VirtualBox to boot first from the downloaded iso file, and “start” the guest machine.
  5. Machine boots and next steps are straightforward: select language, partition disk, select and install packages
  6. The guest machine will then download the needed packages from the internet and will be installed.

Then I made a login to the guest system and play a little with apache, browsing etc…

My expectation was I’ll be able to browse the guest apache from the host system.

It does not work by default installation :(… so, I had to read some docs 😀 .

The idea is that on default install the VirtualBox will create an network adapter of type NAT (Network Address Translation). This type of adapter will permit to the guest to browse om Internet via host IP; but it does not allow connections to the guest.

Just stop the guest operating system and in VirtualBox Manager go to Settings->Network and change the network adapter from NAT to Bridged Adapter like in next picture.

network_select_bridged

If you have more than one network adapter on your host system, be sure that in the same window you have selected the proper one. See Name: field, in my case the active one was the Wireless LAN the one that has internet access, so I’ve selected that one. Be sure that Cable connected checkbox is on.

No other settings are needed.

Click OK and restart your guest operating system.

If you are in a DHCP network (IPs allocated dynamic) do login on the guest operating system and run the ifconfig  command to see what IP was alocated. E.g in my case I got:

>ifconfig

eth0      Link encap:Ethernet  HWaddr 08:00:27:d7:2d:94  
          inet addr:192.168.1.105  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fed7:2d94/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:51 errors:0 dropped:0 overruns:0 frame:0
          TX packets:75 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:14365 (14.0 KiB)  TX bytes:10874 (10.6 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:60 errors:0 dropped:0 overruns:0 frame:0
          TX packets:60 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:23077 (22.5 KiB)  TX bytes:23077 (22.5 KiB)

Then I just go to the host system and browse to http://192.168.1.105/ , and all was fine.

If you are not an a DHCP network (ou are using static IPs), you have to set also the IP on the guest system. The same ifconfig command needs to be used, and it will require root permissions.

More info and details about network adapters available on VirtualBox virtualmanchine cahn be found here http://www.virtualbox.org/manual/ch06.html

Have fun!

Aug 202013
 

One of the most difficult task to do in tcsh is to  redirect the stdout and stderr into separated files. I’m not doing this very often, and because of this I always forget how to do it. Every time when I need to do such a thing I spend tens of minutes trying different combination and reading man/internet pages.

On other shells like bash it is straight forward: my_command > out.txt 2> err.txt  . Such a thing will not work in tcsh, but hey the things are not so complicated. You just have to do (my_command > out.txt ) >& err.txt . Even more, if you want to redirect only the stderr to a file , and want to see what is originally printed on stdout you can do like this: (my_command > /dev/tty ) >& err.txt

Hope that the trick is useful for other visitors who came to this page.

Aug 122012
 

Since years I’m using the putty as ssh client, and I think that it is one of best ever done.
Anyway in the last time I was searching for a SSH client which can handle multiple ssh sessions on the same running instance, to not switch between different windows.

I was looking for something at low cost, but if it is free then it is even better.
Finally I found something: it is mobaxterm from mobatek .
It has what I wanted: tabbed sessions.
If you have multiple connections you do not need to switch between multiple windows, they are tabbed under the same main application.
mobaxterm SFTP tab

    Also, mobaXterm has a lot of other feature, most used be my are:

  • SFTP connection, all he time when you open a ssh connection you will get a SFTP connection too. Continue reading »
 Posted by at 9:55 PM
Aug 102012
 

Very often on unix environment we have to deal with symlinks (aka soft links – reference to other files).

Because of different reason the referenced file may be moved or removed, but the  symlink still points to the old file.

Such situations can lead to unexpected errors: e.g if your symlink points to an executable and the referenced file was deleted then you will get “Permission denied” message, and you will ask yourself: why it does not work ,couple of days ago it was just fine; and the file is there ?!.

Because of this few years ago I’ve made a small script to look for dead links.
Usually I start this script during weekend, and Monday morning I’m just looking on the reports.
Continue reading »